#include<stdio.h>
#include<stdlib.h>
struct node
{
int key;
struct node *left;
struct node *right;
};
struct node *getNode(int val)
{
struct node *newNode;
newNode = malloc(sizeof(struct node));
newNode->key = val;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
struct node *insertNode(struct node *root, int val)
{
if(root == NULL)
return getNode(val);
if(root->key < val)
root->right = insertNode(root->right,val);
if(root->key > val)
root->left = insertNode(root->left,val);
return root;
}
void postorder(struct node *root)
{
if(root == NULL)
return;
postorder(root->left);
postorder(root->right);
printf("%d ",root->key);
}
int main()
{
struct node *root = NULL;
root = insertNode(root,50);
root = insertNode(root, 20);
root = insertNode(root, 55);
root = insertNode(root, 60);
root = insertNode(root, 30);
root = insertNode(root, 25);
root = insertNode(root, 27);
root = insertNode(root, 109);
root = insertNode(root, -10);
root = insertNode(root, 45);
root = insertNode(root, 70);
postorder(root);
return 0;
}