-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBST implementation.cpp
More file actions
57 lines (39 loc) · 891 Bytes
/
Copy pathBST implementation.cpp
File metadata and controls
57 lines (39 loc) · 891 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<string>
using namespace std;
struct BSTNode
{
int data;
BSTNode *left;
BSTNode *right;
};
struct BSTNode *GetNewNode(int data)
{
struct BSTNode *NewNode = new BSTNode();
NewNode->data=data;
NewNode->left = NULL ;
NewNode->right = NULL;
return NewNode;
}
struct BSTNode *Insert(BSTNode* root, int data)
{
if(root==NULL)
root= GetNewNode(data);
else if(data <= root->data)
root->left = Insert(root->left , data);
else
root->right = Insert(root->right , data);
return root;
}
int main()
{
struct BSTNode *rootPtr = NULL;
rootPtr = Insert(rootPtr , 5);
rootPtr = Insert(rootPtr , 7);
rootPtr = Insert(rootPtr , 4);
rootPtr = Insert(rootPtr , 15);
rootPtr = Insert(rootPtr , 17);
rootPtr = Insert(rootPtr , 14);
rootPtr = Insert(rootPtr , 11);
return 0;
}