Challenge 2: Reverse a Stack
Given a stack, reverse the contents of the stack.
We'll cover the following
Problem Statement
Implement a function that takes a stack testVariable
and reverses it. Make sure you do not create any other extra stack or data structure.
Helper functions are provided in the file
stack.py
. Have a look at it before implementing your solution.
Input
A variable testVariable
that contains a stack.
Output
No explicit output. Just reverse the contents of the stack.
Sample Input
8, 5, 3, 2
Sample Output
No explicit output. The contents of the stack will be reversed. For the given sample input the contents of the stack will be 2, 3, 5, 8
.
Try it Yourself
Try to attempt this challenge by yourself before moving on to the solution. Good luck!
main.py
stack.py
import stack as sdef reverse(testVariable) :# Write your code herereturn None
In the next lesson, we have a solution review of this problem.