i have to delete a node in a link list and the prototype for the delete function is like this
void deleteNode(struct node**, int pos). "Pos " is the position of the specified node in the list.
And have to write it with all boundry condiotions.
well it is a singly linked list
this is the function...
void deletenode(struct **start, int pos)
{
struct node *tmp;
int i;
//test if the node is empty
if(*start == NULL )
{
printf("List empty");
return ;
}
//test if the node is 1st node
tmp=*start;
if(tmp-link == null)
{
if(pos==1)
{
free(*start);
*start=null;
return;
}
printf("not enough node");
return ;
}
for(i=1;i<(pos-1);i++)
{
//if end comes before pos, then this will take care
if(tmp->link == null && (i<(pos-2))
{
printf("Not enough nodes in the list");
return ;
}
tmp=tmp->link;
}
}
well this much i did, can any one correct the solution and handle the condition when the node to be deleted is the last node