-
Notifications
You must be signed in to change notification settings - Fork 0
/
BINARYTR.BAK
66 lines (59 loc) · 1.2 KB
/
BINARYTR.BAK
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
61
62
63
64
65
66
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int data;
struct node* left;
struct node* right;
};
struct node* newNode(int data)
{
struct node* node = (struct node*) malloc(sizeof(struct node));
node->data = data;
node->left=NULL;
node->right=NULL;
return(node);
}
struct node* insert(struct node* node,int data)
{
if(node==NULL)
return (newNode(data));
else
{
if(data<=node->data)
node->left=insert(node->left,data);
else
node->right=insert(node->right,data);
return node;
}
}
void Value(struct node* node)
{
struct node* currentL = node;
while(currentL->left!=NULL)
{
currentL = currentL->left;
cout<<currentL->data<<"\n";
}
struct node* currentR = node;
while(currentR->right!=NULL)
{
currentR=currentR->right;
cout<<currentR->data<<"\n";
}
}
int main()
{
clrscr();
struct node* root = NULL;
root=insert(root,4);
insert(root,2);
insert(root,5);
insert(root,3);
insert(root,6);
insert(root,6);
Value(root);
getch();
return 0;
}