diff --git a/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.cpp b/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.cpp index 70d0e0e..899e53a 100644 --- a/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.cpp +++ b/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.cpp @@ -163,6 +163,16 @@ void removeNodes2(Node* &head) { } } } +//function for deleting heap allocated memory for all nodes in Linked List after its use +void delete_LL(Node* &head){ + Node* temp; + while(temp->next!=NULL){ + temp=head; + head=head->next; + delete temp; + } + delete temp; +} int main() { Node *head = new Node(1); @@ -180,11 +190,8 @@ int main() { insertAtTail(tail, pow(2,2)); insertAtTail(tail, pow(2,9)); insertAtTail(tail, pow(2,9)); - - printList(head); - - removeNodes1(head); printList(head); + delete_LL(head); return 0; } \ No newline at end of file diff --git a/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.exe b/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.exe new file mode 100644 index 0000000..9a81e35 Binary files /dev/null and b/Lecture-048/2_Remove_Duplicates_In_Unsorted_Linked_List.exe differ