From 6778a75ab40ac9bd693a4c6598414c08fb9a50bc Mon Sep 17 00:00:00 2001 From: poulomihore Date: Fri, 13 Oct 2017 00:37:07 +0530 Subject: [PATCH 1/2] Removed extra hello from output --- deletion_in_linkedlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deletion_in_linkedlist.cpp b/deletion_in_linkedlist.cpp index 52af92e..460f461 100644 --- a/deletion_in_linkedlist.cpp +++ b/deletion_in_linkedlist.cpp @@ -72,7 +72,7 @@ void delete_node(int num,int del) while(dellink; i=i+1; From c031ec13a0c39421e7d691de70724d98934cbb82 Mon Sep 17 00:00:00 2001 From: poulomihore Date: Fri, 13 Oct 2017 17:33:17 +0530 Subject: [PATCH 2/2] Debugged Deletion code in doubly_linked_list --- doubly_linked_list.cpp | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/doubly_linked_list.cpp b/doubly_linked_list.cpp index efc4459..4ed20f1 100644 --- a/doubly_linked_list.cpp +++ b/doubly_linked_list.cpp @@ -121,7 +121,7 @@ void insertbegin(int s) void insertend(int s) { struct Node *temp=head; - struct Node*prev1; + struct Node* prev1; while(temp!=NULL) { prev1=temp; @@ -140,34 +140,33 @@ void insertend(int s) void delete_node(int del) { struct Node *temp=head; - struct Node *prev1; if (head->data==del) { - temp=head->next; - temp->prev=NULL; - free(temp); + if(head->next==NULL){ + free(temp); + head=NULL; } - else - temp=temp->next; - if(temp->next!=NULL) - { - while(temp->data!=del) - { - prev1=temp; - temp=temp->next; + else{ + head->next->prev=NULL; + head=head->next; + free(temp); } - - struct Node *temp1=temp->next; - prev1->next=temp->next; - temp1->prev=temp->prev; - free(temp); } - else - { - temp=temp->prev; - temp->next==NULL; + else{ + while(temp->next!=NULL){ + if(temp->data==del){ + temp->prev->next=temp->next; + temp->next->prev=temp->prev; + free(temp); + } + else temp=temp->next; + } + if(temp->data==del){ + temp->prev->next=NULL; free(temp); } + } + display(); }