#include<stdio.h>
#include<stdlib.h>

struct node
{
 int data;
 struct node *left,*right;
};

void create(struct node **p,int d)
{
 if(*p==NULL)
   {
    *p=(struct node *)malloc(sizeof(struct node));
    (*p)->data=d;
    (*p)->left=NULL;
    (*p)->right=NULL;
   }
 else
   {
    if(d<(*p)->data)
      {
       create(&((*p)->left),d);
      }
    else
      {
       create(&((*p)->right),d);
      }
   }
}

void preorder(struct node *p)
{
 if(p!=NULL)
   {
    printf("\n%d",p->data);
    preorder(p->left);
    preorder(p->right);
   }
}



void postorder(struct node *p)
{
 if(p!=NULL)
   {
    postorder(p->left);
    postorder(p->right);
    printf("\n%d",p->data);
   }
}

void copy(struct node *rt,struct node **p)
{
 if(rt!=NULL)
   {
    *p=(struct node *)malloc(sizeof(struct node));
    (*p)->data=rt->data;
    (*p)->left=rt->left;
    (*p)->right=rt->right;
    copy(rt->left,&((*p)->left));
    copy(rt->right,&((*p)->right));
   }
}

void main()
{
 struct node *first=NULL,*second=NULL;
 int ch,d;
 do
  {
   printf("\nenter your choice:\n");
   printf("1.create binary tree\n2.preorder\n3.postorder\n4.copy tree\n5.exit\n");
   scanf("%d",&ch);
   switch(ch)
    {
     case 1: printf("\nenter data:");
             scanf("%d",&d);
             create(&first,d);
             break;

     case 2: preorder(first);
             break;

     case 3: postorder(first);
             break;

     case 4: copy(first,&second);
             printf("\nrrrrrrrrrrrrrr\n");
             preorder(second);
             break;
    }
  }
 while(ch!=5);
}


