-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5PreOrderTraversal.cpp
More file actions
42 lines (37 loc) · 819 Bytes
/
Copy path5PreOrderTraversal.cpp
File metadata and controls
42 lines (37 loc) · 819 Bytes
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
#include <bits/stdc++.h>
using namespace std;
struct Node
{
/* data */
int data;
Node* left;
Node* right;
Node(int val)
{
data = val;
left = right = NULL;
}
};
void PrintPreOrderTraversal(Node* root)
{
if(root == NULL)
{
return;
}
cout<<root->data<<" ";
PrintPreOrderTraversal(root->left);
PrintPreOrderTraversal(root->right);
}
int main()
{
struct Node* root = new Node(2);
root->left = new Node(5);
root->right = new Node(7);
root->right->left = new Node(9);
root->right->left->left = new Node(2);
root->right->left->right = new Node(3);
root->right->right = new Node(1);
root->right->left->right->left = new Node(1);
root->right->left->right->right = new Node(4);
PrintPreOrderTraversal(root);
}