function for constructing a tree from inorder and preorder
struct treenode * construct(struct listnode *inptr,struct listnode * preptr ,int num)
{
struct treenode *temp;
struct listnode *q;
int i,j;
if(num==0)
return NULL;
temp=(struct treenode *)malloc(sizeof(struct treenode));
temp->info=preptr->info;
temp->left=NULL;
temp->right=NULL;
if(num==1)/*if only one node in tree*/
return temp;
q=inptr;
for(i=q;q->info!=preptr->info;i++)
q=q->next;
/*now q points to root node in inorder list and the number of nodes in its left tree is i*/
/*for left subtree*/
temp->lchild=construct(inptr,preptr->next,i);
/*for right subtree*/
for(j=1;j<=i+1;j++)
preptr=preptr->next;
temp->rchild=construct(q->next,preptr,num-i-1);//unbale to understand this step as after node G construction value of i and num would be same this would result in -1
return temp;
}/*end of construct */