This is a linked list homework where I need to write a function to convert a string into another string depending on the contents of the original string (e.g. * = backspace, \ = enter, # = del whole line).
I'm given a class Stack with push() pop() and peek(), and I'm meant to use them to store the characters from the string into a stack and then return the stack to reveal the final output.
However when I return the stack, i get the reverse of the output that I am expecting, due to the FILO concept of stacks.
So, I tried to reverse the stack by creating another stack, but the output im getting is NoneNoneNoneNone... , I believe this is due pop() not actually pushing into the new stack? Perhaps I'm meant to use peek instead? I'm sure I'm missing something really obvious, but I cant seem to understand where I'm going wrong.
reverse_stack = Stack()
while not stack.isEmpty():
reverse_stack.push(stack.pop())
return reverse_stack