builds a Binary Tree taking (int) value as an argument and returns the root to the tree built.
| 29 | |
| 30 | //builds a Binary Tree taking (int) value as an argument and returns the root to the tree built. |
| 31 | Tree* buildTree(int val) |
| 32 | { |
| 33 | if(this==nullptr) |
| 34 | { |
| 35 | Tree *temp = new Tree(val); |
| 36 | return temp; |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | Tree *temp=nullptr; |
| 41 | if(this->val>val) |
| 42 | { |
| 43 | temp=this->left->buildTree(val); |
| 44 | this->left=temp; |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | temp=this->right->buildTree(val); |
| 49 | this->right=temp; |
| 50 | } |
| 51 | return this; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | //RECURSIVE DFS PREORDER |
| 56 | void preOrder() |