-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryTree.cpp
60 lines (46 loc) · 1.07 KB
/
BinaryTree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
struct Node{
int val;
Node *left;
Node *right;
};
Node *addNode(int v){
Node *newNode = new Node;
newNode->val = v;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
void inOrder(Node *root){
if(root!=NULL){
inOrder(root->left);
cout<<root->val<<"->";
inOrder(root->right);
}
}
void preOrder(Node *root){
if(root!=NULL){
cout<<root->val<<"->";
preOrder(root->left);
preOrder(root->right);
}
}
int main(){
Node *root = NULL;
root = addNode(12);
root->left = addNode(7);
root->right = addNode(3);
root->left->left = addNode(1);
root->left->right = addNode(5);
root->right->left = addNode(8);
root->right->right = addNode(11);
root->right->right->left = addNode(13);
cout<<"-----Inorder-------"<<endl;
inOrder(root);
cout<<endl;
cout<<"---------PreOrder----"<<endl;
preOrder(root);
cout<<endl;
return 0;
}