I have written the below code to remove a node from a single linked list. Now need some help to get farther. What am I missing?
[code]
int deleteItem(struct node** headRef, int item)
{
struct node* current = *headRef;
struct node* tmp;
int count = 0;
if(current == NULL)
return 1;
if((item-1) == 0)
{
tmp = current->next;
free(current);
*headRef = tmp;
}
else
{
while(count < item-1)
{
tmp = current->next->next;
current = current->next;
free(current);
*headRef = tmp->next;
count++;
}
}
return 0;
}
Code:int deleteItem(struct node** headRef, int item) { struct node* current = *headRef; struct node* tmp; int count = 0; if(current == NULL) return 1; if((item-1) == 0) { tmp = current->next; free(current); *headRef = tmp; } else { while(count < item-1) { tmp = current->next->next; current = current->next; free(current); *headRef = tmp->next; count++; } } return 0; }