Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your Name: TA\'s Name: 6. (15 pts) Write a destroyList () member function for th

ID: 3730221 • Letter: Y

Question

Your Name: TA's Name: 6. (15 pts) Write a destroyList () member function for the class List (dynamically linked) that does not accept any arguments and does not return a value. This function should iteratively (using just a loop, not recursion) remove every Node in the list and set the head pointer back to NULL. Given: a class ListNode with the following private data members: ListNode "mpNext; int mData; and a class List with the following private data member: ListNode mpHead; and the class List is a friend of class ListNode. The friendship allows the List class to access Node private data members directly. No need to use ListNode getters/setters. bool sta Mull

Explanation / Answer

void destroyList() {
   Node *p;
   Node *temp = mpHead;
   while(temp != NULL) {
       p = temp;
       temp = temp->mpNext;
       delete p;
   }
   mpHead = NULL;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote