program:
node *delete(node *head)
{
node *find(node *p, int a);
int key; /* item to be deleted */
node *n1; /* pointer to node preceding key node */
node *p; /* temporary pointer */
printf("\n What is the item (number) to be deleted?");
scanf("%d", &key);
if(head->number == key) /* first node to be deleted) */
{
p = head->next; /* pointer to 2nd node in list */
free(head); /* release space of key node */
head = p; /* make head to point to 1st node */
}
else
{
n1 = find(head, key);
if(n1 == NULL)
printf("\n key not found \n");
else /* delete key node */
{
p = n1->
next->
next; /* pointer to the node following the keynode */
free(n1->next); /* free key node */
n1->
next = p; /* establish link */
}
}
return(head);
}
/* USE FUNCTION find() HERE *
node *delete(node *head)
{
node *find(node *p, int a);
int key; /* item to be deleted */
node *n1; /* pointer to node preceding key node */
node *p; /* temporary pointer */
printf("\n What is the item (number) to be deleted?");
scanf("%d", &key);
if(head->number == key) /* first node to be deleted) */
{
p = head->next; /* pointer to 2nd node in list */
free(head); /* release space of key node */
head = p; /* make head to point to 1st node */
}
else
{
n1 = find(head, key);
if(n1 == NULL)
printf("\n key not found \n");
else /* delete key node */
{
p = n1->
next->
next; /* pointer to the node following the keynode */
free(n1->next); /* free key node */
n1->
next = p; /* establish link */
}
}
return(head);
}
/* USE FUNCTION find() HERE *
No comments:
Post a Comment