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! 12Explanation / 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;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.