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

C++ data structure assignment For the Singly-Linked List class at: SLinkedList.h

ID: 3812040 • Letter: C

Question

C++ data structure assignment

For the Singly-Linked List class at:

SLinkedList.h

}

Add a method void SLinkedList::printReverse() that prints every element in the linked list in reverse (i.e., the first node is printed last). Do not use recursion but instead use a (array-based) stack as a temporary data structure. An implementation of an array-based stack and an example of how to use it are given here:

ArrayStack.h

}

ArrayStack_main.cpp

}

Show only this new method:

May I have screen shot if possible?

// Code from:

Explanation / Answer

The following is the simpler one.

void LinkedList::reversedLinkedList()
{
if(head == NULL) return;

Node *prev = NULL, *current = NULL, *next = NULL;
current = head;
while(current != NULL){
next = current->next;
current->next = prev;
prev = current;
current = next;
}
// now let the head point at the last node (prev)
head = prev;
}

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