Question: I need help my code here. It has memory leaks and I don't know how to fix them. ---------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------- HERES MY CODE: ---------------------------------------------------------------------------------------------------------------------------- In
I need help my code here. It has memory leaks and I don't know how to fix them.
----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------
HERES MY CODE:











----------------------------------------------------------------------------------------------------------------------------






![index); T \& operator [] (int index); 1:Testing Remove() function Output differs.](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f507393b657_20066f50738c9712.jpg)





In this last part you are going to implement various functions to remove nodes from the list, the other two members of the Big Three, as well as an alternate way of iterating through your nodes to print them using recursion. You'll implement the following: Removal functions - RemoveHead0 - RemoveTail() - RemoveAt( - Removes - Clear0 Big Three - Copy Constructor - operator= Recursive Print Functions - PrintForwardRecursive0 - PrintReverseRecursive() \#pragma once \#include using namespace std; template typename T class LinkedList \{ public: struct Node \{ T data; Node * next; Node * prev; Node * searchNext(unsigned int index) \{ if (index ==0 ) \{ return this; \} else \{ index--; return next searchNext (index); \} \} \} void PrintForward() const; void RemoveNode(Node* node); void PrintReverse() const; unsigned int NodeCount () const; void AddHead(const T \& data); void AddTail (const T \& data); LinkedList(); LinkedList(const LinkedList \& list); rLinkedList (); void AddNodesHead(const T data, unsigned int count); void AddNodesTail(const T data, unsigned int count); void Clear(); const Node * Head() const; Node * Head(); const Node * Tail() const; Node * Tail(); const Node * GetNode(int index) const; Node * GetNode(int index); T \& operator [] (int index); 1:Testing Remove() function Output differs. See highlights below. Special character legend Input =====Testing Remove() functionality===== Initial list: Test RemoveMe to RemoveMe find RemoveMe all RemoveMe matching RemoveMe nodes RemoveMe completed RemoveMe with RemoveMe no RemoveMe "RemoveMe" RemoveMe nodes RemoveMe remaining. Nodes removed: 11 Removing RemoveMe from the list. Removed 11 nodes from the list. Test to find all matching nodes completed with no "RemoveMe" nodes remaining. Nodes removed: 11 Leaks found: 2 allocations ( 96 bytes). unknown:unknown ():0 memory leak: memory was not deallocated. unknown:unknown ():0 memory leak: memory was not deallocated. Removing RemoveMe from the list again. Nodes removed: 0 L =====Testing Remove() functionality===== Initial list: Test RemoveMe to RemoveMe find RemoveMe all RemoveMe matching RemoveMe nodes RemoveMe completed RemoveMe with RemoveMe no RemoveMe "RemoveMe" RemoveMe nodes RemoveMe remaining. Removing RemoveMe from the list. Removed 11 nodes from the list. Test Expected output nodes 2:Testing RemoveHead() and RemoveTail() functions Output differs. See highlights below. Input ===== Testing RemoveHead()/RemoveTail () functionality===== Initial list: 0 5 10 15 ==== Testing RemoveHead()/RemoveTail() functionality ===== Initial list: 0 5 10 15 20 25 30 35 40 45 50 55 60 65 Removing 2 Tail and 2 Head Nodes... 10 15 20 25 30 35 45 50 55 LEAkER: errors found! Leaks found: 2 allocations (48 bytes). unknown: unknown():0 memory leak: memory was not deallocated. unknown: unknown():0 memory leak: memory was not deallocated. I ===== Testing RemoveHead()/RemoveTail() functionality==== Initial list: 0 5 10 15 20 25 30 35 40 45 50 55 60 Removing 2 Tail and 2 Head Nodes 10 15 20 25 3:Testing RemoveAt ( and clearing with RemoveHead)/RemoveTail( Output differs. See highlights below. Input ===== Testing RemoveAt() and clearing with RemoveHead()/Removetail() func Initial list: Batman RemoveMe Superman RemoveMe Wonder Woman RemoveMe The Flash Removing using RemoveAt()... Batman Superman Wonder Woman The Flash Attempting to remove out of range using RemoveAt () .. Attempt to RemoveAt ( 100) failed. Clearing list using RemoveHead() ... List is empty! Adding additional nodes... Robin Batgirl Nightwing Red Hood Bluebird Clearing list using RemoveTail() ... List is empty! L LeAkER: errors found!d Leaks found: 2 allocations ( 96 bytes). unknown: unknown():0 memory leak: memory was not deallocated. unknown: unknown():0 memory leak: memory was not deallocated. =====Testing RemoveAt() and clearing with RemoveHead()/RemoveTail() func Initial list: Batman RemoveMe Superman RemoveMe Wonder Woman RemoveMe The Flash ====-Testing RemoveAt() and clearing with RemoveHead()/RemoveTail() fun Initial list: Batman RemoveMe Superman RemoveMe Wonder Woman RemoveMe The Flash Removing using RemoveAt() .. Batman Superman Wonder Woman The Flash Attempting to remove out of range using RemoveAt()... Attempt to RemoveAt (100) failed. Clearing list using RemoveHead()... List is empty! Adding additional nodes... Robin Batgirl Nightwing Red Hood Bluebird Clearing list using RemoveTail() .. Initial list: 2 4 8 16 32 64 128 256 512 1024 Printing recursively forward from 64: 64 128 256 512 1024 Printing recursively in reverse from 512 : 512 256 128 64 32 8 4 2 4 LEAKER: errors found! Leaks found: 2 allocations ( 48 bytes). unknown:unknown():0 memory leak: memory was not deallocated. unknown:unknown():0 memory leak: memory was not deallocated. 643216842
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
