Page 37 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 37
Advanced Data Structure and Algorithms
Notes printf(“ The list before deletion id\n”);
printlist ( start );
printf(“% \n Enter the node no \n”);
scanf ( “ %d”,&n);
start = delet (start , n );
printf(“ The list after deletion is\n”);
printlist ( start );
}
/* a function to delete the specified node*/
struct node *delet ( struct node *p, int node_no )
{
struct node *prev, *curr ;
int i;
if (p == NULL )
{
printf(“There is no node to be deleted \n”);
}
else
{
if ( node_no > length (p))
{
printf(“Error\n”);
}
else
{
prev = NULL;
curr = p;
i = 1 ;
while ( i < node_no )
{
prev = curr;
curr = curr-> link;
i = i+1;
}
if ( prev == NULL )
{
p = curr -> link;
free ( curr );
}
else
32 LOVELY PROFESSIONAL UNIVERSITY