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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.