Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Tree
//g++ 7.4.0 #include <iostream> #include <bits/stdc++.h> using namespace std; class Tree { private: Tree *left, *right; int data; public: Tree(int value) { this->left = this->right = NULL; this->data = value; } Tree *insert(Tree *node, int value) { if(node == NULL) return new Tree(value); if(node->data>value) node->left = insert(node->left, value); else node->right = insert(node->right, value); return node; } void traverseInOrder(Tree *node) { if(node == NULL) return; traverseInOrder(node->left); cout<<node->data<<" "; traverseInOrder(node->right); } }; int main() { Tree *root = new Tree(35); root = root->insert(root,10); root = root->insert(root,45); root->traverseInOrder(root); }
run
|
edit
|
history
|
help
3
typecasting
MovConstrAssign2
strict aliasing
MAC
override
ArrAdSubMul
cpp permutations
pi with cmath
diamond
C++ - Chained Methods