def push(self, value): if self.stacksSoFar[-1].nodesSoFar == self.maxStackLengthAllowed: self.stacksSoFar.append(MyStack()) self.stacksSoFar[-1].push(value)
def __init__(self): # append the first stack to the empty array that will hold O(n) stacks self.stacksSoFar.append(MyStack())
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()
from Chapter_3.MyStack import * ms = MyStack()
def reversedStack(self, stack): tempStack = MyStack() while not stack.isEmpty(): tempStack.push(stack.pop()) return tempStack
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()
def createThreeStacksInSingleArray(self): self.singleArrayStacks.append(MyStack()) self.singleArrayStacks.append(MyStack()) self.singleArrayStacks.append(MyStack())