-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.h
More file actions
55 lines (48 loc) · 838 Bytes
/
tree.h
File metadata and controls
55 lines (48 loc) · 838 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
#ifndef TREE_H_
#define TREE_H_
#include <stdlib.h>
#include <stdio.h>
struct TreeNode
{
int value;
struct TreeNode *left;
struct TreeNode *right;
struct TreeNode *next;
};
typedef struct TreeNode* Node;
Node Insert(Node root,int val)
{
if(root == NULL)
{
Node temp;
temp = (struct TreeNode *)malloc(sizeof(struct TreeNode));
temp->value = val;
temp->left = NULL;
temp->right = NULL;
temp->next = NULL;
return temp;
}
if(val > root->value)
root->right = Insert(root->right,val);
else
root->left = Insert(root->left,val);
return root;
}
void PrintTree(Node root)
{
if(!root)
return;
PrintTree(root->left);
printf("%d",root->value);
PrintTree(root->right);
}
void DestroyTree(Node root)
{
if(root)
{
DestroyTree(root->left);
DestroyTree(root->right);
free(root);
}
}
#endif /* TREE_H_ */