###Memory Leak###
Memory Leak
These lines here create a memory leak, because you allocate a node and never free it:
// creates a temp node and sets it to head Node *temp = new Node; temp = head;
You don't need to allocate another node there, because you aren't actually ever using it. You can just set the temp
pointer directly to head
:
Node *temp = head;
###Memory Leak###
These lines here create a memory leak, because you allocate a node and never free it:
// creates a temp node and sets it to head Node *temp = new Node; temp = head;
You don't need to allocate another node there, because you aren't actually ever using it. You can just set the temp
pointer directly to head
:
Node *temp = head;
Memory Leak
These lines here create a memory leak, because you allocate a node and never free it:
// creates a temp node and sets it to head Node *temp = new Node; temp = head;
You don't need to allocate another node there, because you aren't actually ever using it. You can just set the temp
pointer directly to head
:
Node *temp = head;
###Memory Leak###
These lines here create a memory leak, because you allocate a node and never free it:
// creates a temp node and sets it to head Node *temp = new Node; temp = head;
You don't need to allocate another node there, because you aren't actually ever using it. You can just set the temp
pointer directly to head
:
Node *temp = head;