From 1f13bb37bcdfba61c3d98e254eeca24264873e21 Mon Sep 17 00:00:00 2001 From: Sagar Mishra Date: Tue, 4 Aug 2020 09:48:54 +0530 Subject: [PATCH] Update DoublyLinkedList.c On line no 183, I have changed this --> k < position -1 to this --> k < position because if there are 5 elements in the list and you try to delete the 6th one, k < position -1, because of this condition last element was getting removed even if the position does not exist. I have added one more case in the end --- src/Chapter_03_Linked_Lists/DoublyLinkedList.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Chapter_03_Linked_Lists/DoublyLinkedList.c b/src/Chapter_03_Linked_Lists/DoublyLinkedList.c index fb3e007..a266587 100644 --- a/src/Chapter_03_Linked_Lists/DoublyLinkedList.c +++ b/src/Chapter_03_Linked_Lists/DoublyLinkedList.c @@ -180,7 +180,7 @@ void delete(struct DLLNode **head, int position) { temp = temp->next; k++; } - if(k < position-1){ + if(k < position){ printf("Desired position does not exist\n"); return; } @@ -234,5 +234,9 @@ int main(){ printf("List length is %d \n",length(head)); printList(head); printf("\n"); + delete(&head, 6); + printf("List length is %d \n",length(head)); + printList(head); + printf("\n"); return 0; }