def __init__(self): # Initialise the queue self.enqstack = Stack() self.deqstack = Stack() self.size = 0
def push(self, item): if self.list[-1].size() == self.stackSize: self.list.append(Stack()) self.list[-1].push(item)
def __init__(self): self.stack1 = Stack() self.stack2 = Stack()
from Recursividad import suma_lista_rec,countdown,eliminar_pila from Stack import Stack print("Prueba suma lista recursiva") datos = [4,2,3,5] res = suma_lista_rec(datos) print(f"La suma de la lista es {res}") print("\nPrueba Cuentaregresiva") countdown(20) print("\nPrueba ADT Stack") s = Stack() s.push(100) s.push(50) s.push(30) s.push(120) s.push(230) s.push(10) print("\nCaso Base") s.to_string() eliminar_pila(s) print("\nCaso despues de la funcion") s.to_string()
def __init__(self, stack_size): super().__init__(stack_size) self.min_stack = Stack(stack_size)
def __init__(self, *args, **kwargs): super(StackWithMin, self).__init__(*args, **kwargs) self.min_stack = Stack()
def __init__(self): self.enqueue_stack = Stack() self.dequeue_stack = Stack()
from Stack import Stack from Element import Element from conjuctivePredicatesCheck import* from checkPreconditions import* startState = "ON(C,B)^ONTABLE(B)^ONTABLE(A)^CLEAR(A)^CLEAR(C)".split("^") endState = "ON(A,B)^CLEAR(A)^ONTABLE(C)^ON(B,C)".split("^") goalstack = Stack() currentState = Stack() steps = Stack() Arm = Stack() goalstack.push(endState) for i in endState: goalstack.push(i) #store goal into stack for i in startState: #store initial state to currentstate currentState.push(i) while(not goalstack.isEmpty()): N = goalstack.peek() print goalstack.toString() print currentState.toString() print steps.toString() print Arm.toString() print "\n" if N in currentState.__contains__():
def setUp(self): self.stack = Stack() print(f"setUp: stack size: {self.stack.size()} in {self.stack}")
def main(): print("-----TEST 1-----") stack1 = Stack() stack1.push(2) print(stack1) stack1.pop() print(stack1) stack1.push(4) print(stack1) stack1.push(8) print("Top: " + str(stack1.top())) stack1.push(5) print("Top: " + str(stack1.top())) stack1.pop() stack1.push(6) print(stack1) stack1.pop() stack1.pop() stack1.push(7) print(stack1) print("\n-----TEST 2-----") stack2 = Stack() stack2.push(2) stack2.push(5) stack2.push(14) stack2.push(7) stack2.push(3) stack2.push(7) print(stack2) stack2.push(89) stack2.push(23) stack2.push(7) print(stack2) stack2.pop() stack2.pop() print(stack2) stack2.push(8) stack2.push(9) print(stack2) print("Top: " + str(stack2.top())) stack2.push(15) stack2.push(3) stack2.push(7) stack2.push(8) print("Top: " + str(stack2.top())) stack2.push(45) print(stack2) stack2.push(34) stack2.push(2) stack2.push(5) print("Top: " + str(stack2.top())) stack2.push(9) print("Top: " + str(stack2.top())) print(stack2) print("\n-----TEST 3-----") print(Palindrome("level")) print(Palindrome("Kayak")) print(Palindrome("made")) print(Palindrome("Eva, can I see bees in a cave?")) print(Palindrome("I did, did I?")) print(Palindrome("noscope36063epocson")) print(Palindrome("noscope560")) stack2 = Stack()
def test_init(self): stack = Stack() assert stack.top is None
def __init__(self, source): self.pointer = [0] self.stacks = (Stack(), Stack()) self.scope = [] self.source = [atomize(source)] self.functions = [atomize(source)]
from Stack import Stack def sort_stack(unsorted, sorted): size = len(unsorted) while len(sorted) != size: curr = unsorted.pop() if len(sorted) == 0: sorted.push(curr) else: while sorted.peek() > curr: temp = sorted.pop() unsorted.push(temp) sorted.push(curr) return sorted sorted = Stack() unsorted = Stack() unsorted.push_multiple([4, 8, 2, 9, 1]) sort_stack(unsorted, sorted) print(sorted)
from Stack import Stack word = raw_input("Enter a word: ") word = word.upper() wordStack = Stack() for letter in word: wordStack.push(letter) print "\n\n" reverse = "" while not wordStack.isEmpty(): reverse += str(wordStack.pop()) print reverse if word == reverse: print word, "is a palindrome ... :-)" else: print word, "is a NOT a palindrome ... :-)" print "\n\n"
title = row[1].strip() name = row[2].strip() last_name = row[3].strip() st = Student(str(id), str(title), str(name), str(last_name)) students.append( st) #put the st which is student object to the students list line_cnt = line_cnt + 1 print( "===================================Stack data structure===================================" ) print( '-----------------------------------create stack------------------------------' ) stStudent = Stack(45) print( '-----------------------------------Normal Flow------------------------------' ) for i in students: print("push the ", i.__str__(), "Which is student object to the stack") stStudent.push(i) while not stStudent.is_empty(): print("This is the top value of the stack: ", stStudent.peek().__str__()) print("Then take it out of the top stack by pop() it") stStudent.pop() print( '-----------------------------------Using pop all()------------------------------'
def __init__(self): # initialize class with a stack a dictionary self.stack = Stack() self.dict = {}
def setUp(self): self.__deque = get_deque() self.__stack = Stack() self.__queue = Queue()
def __init__(self): # call superclass constructor and make a news stack Publisher.__init__(self) self.news_stack = Stack()
def rev_String(String): stack = Stack() for char in String: stack.push(char) while not stack.is_empty(): print(stack.pop() + " ")
def __init__(self, source, output, *args): self.stack = Stack(args) self.source = source self.scope = [] self.pointer = 0 self.output = output
def __init__(self): super().__init__() self.minstack = Stack()
from Queue_head import Queue from Stack import Stack myQ = Queue() myS = Stack() for data in [1,2,3,4,5]: myQ.enQueue(data) myS.push(data) print("Queue:") print(myQ) print("\nStack: ") print(myS) print("Removing first element: ") print("Queue returned: %s"%myQ.deQueue()) print("Stack returned: %s"%myS.pop()) print("\nQueue:") print(myQ) print("\nStack: ") print(myS) print("Adding a 6 element:") myQ.enQueue(6) myS.push(6) print("\nQueue:")
from Stack import Stack stack = Stack(int) #Initialise a stack object with the data type. #Gotta love them true loops. while True: try: intInput = int(input("Please enter a non-negative integer to convert to binary: ")) #Retrieve the terminal input. Convert to int. except Exception: break; if intInput < 0: break #Push these remainders and pop em out like a baby afterwards. A binary baby. while intInput != 0: stack.push(intInput % 2) intInput //= 2 while stack.top is not None: print(stack.pop(), end="") print("")
def __init__(self): # Initialise the queue # YOUR CODE HERE self.item1 = Stack() self.item2 = Stack()
def __init__(self, stackSize=5): self.list = [] self.list.append(Stack()) self.stackSize = stackSize
from Stack import Stack st = Stack() def decimal_to_binary(decimal): while decimal: decimal, mod = decimal // 2, decimal % 2 st.push(mod) bin = '' while not st.is_empty(): bin += str(st.pop()) return bytes(bin, encoding='utf-8') decimal_to_binary(47)
from Stack import Stack arrayStack = Stack() arrayStack.push(5) # contents: [5] arrayStack.push(3) # contents: [5, 3] print(arrayStack.size()) # contents: [5, 3]; outputs 2 print(arrayStack.pop()) # contents: [5]; outputs 3 print(arrayStack.isEmpty()) # contents: [5]; outputs False print(arrayStack.pop()) # contents: [ ]; outputs 5 print(arrayStack.isEmpty()) # contents: [ ]; outputs True arrayStack.push(7) # contents: [7] arrayStack.push(9) # contents: [7, 9] print(arrayStack.top()) # contents: [7, 9]; outputs 9 arrayStack.push(4) # contents: [7, 9, 4] print(arrayStack.size()) # contents: [7, 9, 4]; outputs 3 print(arrayStack.pop()) # contents: [7, 9]; outputs 4 arrayStack.push(6) # contents: [7, 9, 6]
def __init__(self, n=5): self.currentStack = Stack() self.stackOfStacks = [ ] #does this take extra storage or does the list only contain pointers to the stacks? self.maxHeight = n self.currentHeight = 0
def divOp(): stack.div() operation = { 'pop': popOp, 'add': addOp, 'sub': subOp, 'mul': mulOp, 'div': divOp, } with open("entrada.txt", "r") as textFile: stack = Stack() pushOp = False for line in textFile: for word in line.split(): if pushOp: stack.push(word) pushOp = False elif word == "push": pushOp = True else: try:
def __init__(self): self.main_stack = Stack()