-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_tree.c
More file actions
101 lines (87 loc) · 1.54 KB
/
Copy pathbinary_tree.c
File metadata and controls
101 lines (87 loc) · 1.54 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
#include <stdlib.h>
struct TreeNode
{
int Element;
struct TreeNode* Left;
struct TreeNode* Right;
};
struct TreeNode* MakeEmpty(struct TreeNode* root)
{
if(root != NULL)
{
MakeEmpty(root->Left);
MakeEmpty(root->Right);
free(root);
}
return NULL;
}
struct TreeNode* Insert(struct TreeNode* root, int newNodeElement)
{
if( root == NULL )
{
root = malloc(sizeof(struct TreeNode));
if(root == NULL)
{
}
else
{
root->Element = newNodeElement;
root->Left = NULL;
root->Right = NULL;
}
}
else
{
if(newNodeElement < root->Element)
{
root->Left = Insert(root->Left, newNodeElement);
}
else if(newNodeElement > root->Element)
{
root->Right = Insert(root->Right, newNodeElement);
}
}
return root;
}
struct TreeNode* Delete(struct TreeNode* root, struct TreeNode* deleteNode)
{
return NULL;
}
struct TreeNode* Find(struct TreeNode* root, struct TreeNode* findNode)
{
return NULL;
}
void FirstOrder(struct TreeNode* root)
{
printf("%d\n", root->Element);
if(root->Left != NULL){
FirstOrder(root->Left);
}
if(root->Right != NULL){
FirstOrder(root->Right);
}
}
void MiddleOrder(struct TreeNode* root)
{
if(root->Left != NULL)
{
MiddleOrder(root->Left);
}
printf("%d\n", root->Element);
if(root->Right != NULL)
{
MiddleOrder(root->Right);
}
}
int main(int argc, char** argv)
{
struct TreeNode* root = Insert(NULL, 10);
root = Insert(root, 3);
root = Insert(root, 12);
printf("FirstOrder:\n");
FirstOrder(root);
printf("MiddleOrder:\n");
MiddleOrder(root);
return 0;
}