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

For the Singly-Linked List class at: https://github.com/apanangadan/CSUF-CPSC_13

ID: 3831404 • Letter: F

Question

For the Singly-Linked List class at:

https://github.com/apanangadan/CSUF-CPSC_131/blob/master/SLinkedList.h

Add a method void SLinkedList<E>::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:

https://github.com/apanangadan/CSUF-CPSC_131/blob/master/ArrayStack.h

https://github.com/apanangadan/CSUF-CPSC_131/blob/master/ArrayStack_main.cpp

Show only this new method #include "ArrayStack.h" template

Explanation / Answer

template <typename E>

void SLinkedList<E>::printReverse()

{

int len = size();

If ( len == 0 )

{

cout<<"Empty list";

return;

}

ArrayStack<E> stack(len);

SNode<E>*itr = head;

while (temp)

{

stack.push(temp->elem);

temp = temp->next;

}

stack.printAll();

}