typedef struct node
{
int data;
struct node *next,*prev;
}harsha;
void create_leaf(harsha **pnode,int value)
{
harsha *temp=*pnode;
if(*pnode==NULL)
{
*pnode=(struct node *)malloc(sizeof(struct node));
if(!(*pnode))
{
printf("mem not allocated");
exit(0);
}
(*pnode)->data=value;
(*pnode)->prev=NULL;
(*pnode)->next=NULL;
}
else
{
if(value>(temp->data))
create_leaf(&(temp->next),value);
else if(value<temp->data)
create_leaf(&(temp->prev),value);
}
}
This is function I have written for Inserting the new node into the binary search tree.Is there any problem with my code as my Inorder,Preorder and Postorder traversals are not working fine.
void Inorder_traversal(harsha *pnode) { if(pnode!=NULL) { Inorder_traversal(pnode->prev); printf("%d\t",pnode->data); Inorder_traversal(pnode->next); } else return; }is my Inorder function and if the input is 5 4 8. it is printing 4 5 8 with some big numbers followed by and the program stopped working with out going to other functions postorder and Preorder