-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreeImpl.c
52 lines (43 loc) · 893 Bytes
/
treeImpl.c
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
#include <stdio.h>
#include <malloc.h>
typedef struct Node {
int data;
struct Node* left;
struct Node* right;
} node;
node* newNode(int d){
node* p = (node*)malloc(sizeof(node));
p->data = d;
p->left = NULL;
p->right = NULL;
return p;
}
void printTreeInOrder(node* root){
if(root==NULL) return;
printTreeInOrder(root->left);
printf("%d ",root->data);
printTreeInOrder(root->right);
}
void insert(node** x, int d){
node* new = newNode(d);
if(*x==NULL) *x = new;
else {
}
}
int lookup(node* root, int d){
if(root==NULL)
return 0;
if(d == root->data)
return 1;
if( d < root->data )
return( lookup(root->left, d) );
else
return( lookup(root->right, d) );
}
int main(){
node* root = (node*)malloc(sizeof(node));
root = NULL;
insert(&root, 1);
printTreeInOrder(root);
return 1;
}