def reversedStack(self, stack): tempStack = MyStack() while not stack.isEmpty(): tempStack.push(stack.pop()) return tempStack
from Chapter_3.MyStack import * stack = MyStack() stack.push(1) stack.push(4) stack.push(2) stack.push(5) stack.push(3) stack.push(45) stack.sortStack()
def reversedStack(self, stack): tempStack = MyStack() while not stack.isEmpty(): tempStack.push(stack.pop()) return tempStack def addTheStackNodesToTheQueue(self, queue, stack): addThisNode = stack.top while addThisNode is not None: queue.add(addThisNode.data) addThisNode = addThisNode.next # the stack-1 that holds the nodes to create the queue stack_1 = MyStack() stack_1.push(1) stack_1.push(2) stack_1.push(3) stack_1.printStack() # an extra stack-2 that holds nodes to keep creating the same queue stack_2 = MyStack() stack_2.push(4) stack_2.push(5) stack_2.push(6) stack_2.printStack() # the queue that will be created by the stack nodes thisQueue = MyQueue() # the class that creates the final queue via the stack