Question: C++ The following code is supposed to insert a node at the beginning of a linked list but it has a logical error that creates
C++
The following code is supposed to insert a node at the beginning of a linked list but it has a logical error that creates a memory leak. Which lines should be swapped in order to fix this error?
1. newNode = new Node;
2. newNode->value = 10;
3. newNode->next = nullptr;
4. head = newNode;
5. newNode->next = head;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
