Using recursion, revise the destructor in the class LinkedListso that it deletes each node of the underlying linked chain.

What will be an ideal response?

```
template
LinkedList::~LinkedList()
{
deallocate(headPtr);
headPtr = nullptr;
itemCount = 0;
} // end destructor
// Private method: Deallocates all nodes assigned to the bag.
template
voidLinkedList::deallocate(Node* nextNodePtr)
{
if (nextNodePtr != nullptr)
{
Node* nodeToDeletePtr = nextNodePtr;
nextNodePtr = nextNodePtr->getNext();
delete nodeToDeletePtr;
deallocate(nextNodePtr);
} // end if
} // end deallocate

```

Computer Science & Information Technology

You might also like to view...

The Task Manager can be used to close a nonresponsive program

Indicate whether the statement is true or false

Computer Science & Information Technology

What is a counter? What does it mean to initialize and update a counter in a program?

What will be an ideal response?

Computer Science & Information Technology