-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost_order_recursion.c
55 lines (49 loc) · 1001 Bytes
/
post_order_recursion.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
53
54
55
#include "stdio.h"
#include "stdlib.h"
struct bstnode
{
int data;
struct bstnode* right;
struct bstnode* left;
};
struct bstnode* get_newnode(int data){
struct bstnode* newnode=(struct bstnode*)malloc(sizeof(struct bstnode));
newnode->data=data;
newnode->right=newnode->left=NULL;
return newnode;
}
struct bstnode* insert(struct bstnode* root, int data){
if (root==NULL)
{
root=get_newnode(data);
}
else if(root->data>=data){
root->left=insert(root->left,data);
}
else {
root->right = insert(root->right,data);
}
return root;
}
void postorder(struct bstnode* root){
if (root==NULL)
{
return;
}
postorder(root->left);
postorder(root->right);
printf("%d ",root->data );
}
int main(int argc, char const *argv[])
{
struct bstnode* root=(struct bstnode*)malloc(sizeof(struct bstnode));
root=NULL;
root=insert(root,100);
root=insert(root,110);
root=insert(root,90);
root=insert(root,50);
root=insert(root,200);
root=insert(root,60);
postorder(root);
return 0;
}