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

Your Name: linked) that does not accept any arguments and returns a copy of the

ID: 3735906 • Letter: Y

Question

Your Name: linked) that does not accept any arguments and returns a copy of the integer data in the Node deleted. This function should delete the last Node in the list. TA's Name: rite a deleteNodeAtEnd() member function in C++ for the class Tist (dynamically singly Given: a class Node with the following private data members: Node *mpNext; int mData; and a class List with the following private data member: ListNode "mpHead;// points to the front of the list and the class List is a friend of class Node. The friendship allows the List class to access Node private data members directly. // precondition: list must not be empty! 12

Explanation / Answer

int List::deleteNodeAtEnd() {
   Node *temp = mpHead;
   if(mpHead == NULL) {
       return -1;
   }
   if(mpHead->mpNext == NULL) {
       mpHead = NULL;
       return temp->mData;
   } else {
       while(temp->mpNext->mpNext != NULL) {
           temp = temp->mpNext;
       }
       int ret = temp->mpNext->mData;
       temp->mpNext = NULL;
       return ret;
   }
}

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