Removing all nodes with a certain value in a linked list
By : cltr
Date : March 29 2020, 07:55 AM
hop of those help? The title is pretty self explanatory. Here's the function I've written for this purpose: , What if
|
Removing nodes from a Doubly linked list correctly
By : maerco
Date : March 29 2020, 07:55 AM
Does that help When you delete a node it, you need to both replace the previous node's next pointer with it->next, and replace the next node's previous pointer with it->prev. However, when doing this you must also account for the special cases at the start and end of the list: code :
if (it->prev != NULL)
it->prev->next = it->next;
else
this->first = it->next;
if (it->next != NULL)
it->next->prev = it->prev;
else
this->last = it->prev;
Bool LinkedList_removestr(LinkedList * this, char * str)
{
Node * tmp = NULL;
Node * it = this->first;
Bool Bandera = FALSE;
while (it != NULL)
{
/* Save it->next, because 'it' may be freed */
tmp = it->next;
if (strcmp(it->name, str) == 0)
{
Bandera = TRUE;
/* Adjust next pointer of previous node */
if (it->prev != NULL)
it->prev->next = it->next;
else
this->first = it->next;
/* Adjust previous pointer of next node */
if (it->next != NULL)
it->next->prev = it->prev;
else
this->last = it->prev;
free(it);
}
it = tmp;
}
return Bandera;
}
|
Linked list, removing nodes from front?
By : Virendra Verma
Date : March 29 2020, 07:55 AM
it should still fix some issue , The code could be simplified as this.
|
Removing nodes between two given positions from singly linked list?
By : thiruppathi
Date : March 29 2020, 07:55 AM
hop of those help? To remove all nodes between two nodes on a singly linked list is not super hard. You need two placeholders. You move through the linked list until you find your start node, and set one of the placeholders equal to it. You then move your second placeholder through the remainder of the linked list until you find your second node. Set your first node's -> next parameter equal to the second node, and you've effectively removed everything in between.
|
Having trouble removing all nodes from a linked-list
By : earlung640
Date : March 29 2020, 07:55 AM
With these it helps I created a basic implementation of a linked list and tested your code. It's not particularly pretty, but it works:
|