Автор Сообщение
CathyRoberson    

Guys,

I am having trouble trying to delete the last node in a linked list program. Here is my function but it does not work properly:

void DeleteLastNode(Node *headPointer) {

Node *delFirstNode;
delFirstNode = headPointer->next;

while(delFirstNode != NULL) {

headPointer->next = headPointer->next->next;
if(delFirstNode == NULL) {
free(delFirstNode);
printf(«deleted»);
break;
}
else {
printf(«There are no nodes in the list!\n»);
}
}
}

Could someone please fix this so it works please!

 

William_VRiley    

Write conversationally you have read-write like you speak many times and rolled your eyes. Essay Writers UK Based No one can write like they speak nor is it a pleasant content writing style to begin with. But focus on writing conversationally and with flavor. Write for an audience and keep the audience in front while you do the writing.

edwardwilliam    

I subsequently found out that when present day->next is NULL, this assertion cause segfault. Online Law Essay Help came up with a workaround like under and it worked giving correct output.

macooxi    

Hi, have you fixed the problem? I want to test here.