#include <stdio.h>  
#include <stdlib.h>  

struct bstnode 
{
    int value ;
    struct bstnode*l;
    struct bstnode*r;
}*root=NULL, *temp=NULL, *t2, *t1;

void create();
void insert();
void search (struct bstnode*t2);
void postorder (struct bstnode*t1);

int flag=1;

int main()
{
    int ch;
    printf("\n Operation");
    printf("\n 1.Insert an element in tree\n");
    printf("\n 2.Display \n");
    printf("\n 3.Exit \n");
    while(1)
    {
        printf("\n\n Enter your option:");
        scanf("%d",&ch);
        
        switch(ch)
        {
            case 1: insert();
            break;
            
            case 2: postorder (root);
            break;
            
            case 3: exit(0);
            
            default: printf("Invalid option");
            break;
        }
    }
    return 0;
}
void create()
{
    int data;
    printf("Enter data of node to be Inserted:");
    scanf("%d",&data);
    
    temp= (struct bstnode*) malloc(1*sizeof(struct bstnode));
    temp-> value=data;
    temp->l=temp->r=NULL;
}
void insert()
{
    create();
    if(root==NULL)
     root==temp;
     else
     search(root);
}

void search (struct bstnode*t2)
{
  if((temp->value>t2->value) && (t2->r!=NULL)) 
    {
        search (t2->r);
    }
    
    else if ((temp->value>t2->value) && (t2->r==NULL))
    {
        t2->r=temp;
    }
    
    else if ((temp->value<t2->value)&&(t2->l!=NULL))
    {
        search(t2->l);
    }
    
    else if ((temp->value<t2->value)&&(t2->l==NULL))
    {
        t2->l=temp;
    }
}
    
void postorder (struct bstnode*t1)
{
    void postorder (struct bstnode*t1)
    {
        if(root==NULL)
        {
            printf("no element in a tree is displayed!!!");
            return;
        }
        if(t1->l!=NULL)
        {
            postorder (t1->l);
        }
        if(t1->r!=NULL)
        {
            postorder (t1->r);
        }
        printf("%d",t1->value);
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: