0

Reverse a stack

I need help with my assignment, so basically i need to reverse a stack but without recursion, i need to to do it with the help of a linked list, and I don’t know how I’m supposed to transfer elements from the stack to the linked list and vise versa I have this code so far, but i don’t if it’s correct or if it work: https://code.sololearn.com/cMJ6yUkdou8X/?ref=app

27th Apr 2022, 9:04 PM
Ghazl Sinjab
1 Answer
0
The reversal can be done in a two-step approach: 1. Pop the elements off the stack while storing them at the end of the list. 2. Pushing the elements of the list from front to back to the stack. Instead of reinventing a linked list, it might be easier to use an existing implementation from the standard library: https://en.cppreference.com/w/cpp/container/forward_list https://en.cppreference.com/w/cpp/container/list
27th Apr 2022, 11:43 PM
Shadow
Shadow - avatar