Page 138 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 138
Unit 6: Binary Search Tree and AVL Trees
exit(0); Notes
}
temp2->data = val;
temp2->lchild=temp2->rchild = NULL;
}
else
{
temp2->rchild = (struct tnode*)malloc(sizeof(struct tnode));/ *inserts
the newly created node
as left child*/
temp2 = temp2->rchild;
if(temp2 == NULL)
{
printf(“Cannot allocate\n”);
exit(0);
}
temp2->data = val;
temp2->lchild=temp2->rchild = NULL;
}
}
return(p);
}
void main()
{
struct tnode *root = NULL;
int n,x;
printf(“Enter the number of nodes in the tree\n”);
scanf(“%d”,&n);
while( n - > 0)
{
printf(“Enter the data value\n”);
scanf(“%d”,&x);
root = insert(root,x);
}
printf(“The created tree is :\n”);
inorder1(root);
printf(“\n Enter the value of the node to be deleted\n”);
scanf(“%d”,&n);
root=delete(root,n);
printf(“The tree after deletion is \n”);
inorder1(root);
}
LOVELY PROFESSIONAL UNIVERSITY 133