Page 133 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 133
Advanced Data Structure and Algorithms
Notes else
{
there is no left subtree.,
return (string not found) }
}
else if (key-value value stored in current node)
{
if (right child exists)
{
find-key (key-value, rot child);
}
else
{
there is no right subtree;
return (string not found)
}
}
}
Lab Exercise Program: C program to delete a node, where the data value of the node to be
deleted is known, is as follows:
#include <stdio.h>
#include <stdlib.h>
struct tnode
{
int data;
struct tnode *lchild, *rchild;
};
/* A function to get a pointer to the node whose data value is given
as well as the pointer to its root */
struct tnode *getptr(struct tnode *p, int key, struct tnode **y)
{
struct tnode *temp;
if( p == NULL)
return(NULL);
temp = p;
*y = NULL;
while( temp != NULL)
{
if(temp->data == key)
return(temp);
128 LOVELY PROFESSIONAL UNIVERSITY