Skip to content

Commit

Permalink
Merge pull request #212 from jean553/fix_remove_at_the_end_linked_lis…
Browse files Browse the repository at this point in the history
…t_when_contains_only_one_node

fix the drop at the end of the linked list when it only contains one node
  • Loading branch information
jean553 authored Jan 19, 2018
2 parents 3920fbd + 8490080 commit 51379ec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions linked_list/linked_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ void dropAtTheEndLL(LinkedList* list)
LinkedListNode* node = list->head;
LinkedListNode* newLast = node;

if (sizeLL(list) == 1)
{
free(list->head);

list->head = NULL;

return;
}

while(node->next != NULL)
{
newLast = node;
Expand Down

0 comments on commit 51379ec

Please sign in to comment.