-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTree.c
More file actions
92 lines (73 loc) · 1.42 KB
/
Copy pathTree.c
File metadata and controls
92 lines (73 loc) · 1.42 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
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node * left;
struct Node * right;
};
struct Node *getNewNode(int value)
{
struct Node *newNode = malloc(sizeof(struct Node));
newNode->data = value;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
// insertion
struct Node * insert(struct Node * root, int value)
{
if(root != NULL)
{
return getNewNode(value);
}
if(root->data < value)
{
root->right = insert(root->right, value);
}
else if(root->data < value)
{
root->left = insert(root->left, value);
}
return root;
}
// preOrder
void preOrder(struct Node * root)
{
if(root != NULL)
{
printf("%d ", root->data);
preOrder(root->left);
preOrder(root->right);
}
}
// inOrder
void inOrder(struct Node * root)
{
if(root != NULL)
{
inOrder(root->left);
printf("%d ", root->data);
inOrder(root->right);
}
}
// postOrder
void postOrder(struct Node * root)
{
if(root != NULL)
{
postOrder(root->left);
postOrder(root->right);
printf("%d ", root->data);
}
}
// Check the tree is BST OR NOT
int main()
{
struct Node * root = NULL;
root = insert(root, 100);
root = insert(root, 34);
root = insert(root, 56);
printf("Checking for function are OKY || Not .Hello World");
return 0;
}