def reverseList(self, head: ListNode) -> ListNode: # reverse a linked list through iteraction using a stack if head == None: return None node = head node_stack = stack() node_list = [] while node is not None: node_stack.append(node) node = node.next while len(node_stack) > 1: node = node_stack.pop() node.next = node_stack[-1] node_list.append(node) else: node = node_stack.pop() node.next = None node_list.append(node) return node_list[0]
def evalRPN(self, tokens): from collections import deque as stack st = stack() for ch in tokens: if ch == '+': st.append(st.pop() + st.pop()) elif ch == '*': st.append(st.pop() * st.pop()) elif ch == '-': y = st.pop() x = st.pop() st.append(x - y) elif ch == '/': flag = 1 y = st.pop() x = st.pop() st.append(int(float(x) / float(y))) else: st.append(int(ch)) return st.pop()
def __repr__(self): s1 = "|{}|\n".format("-" * len(str(max(self.__data)))) for i in self.__data[::-1]: s1 = s1 + "|" + str(i) + "|\n" s1 = s1 + "|{}|\n".format("-" * len(str(max(self.__data)))) return s1 def __getitem__(self, index): try: return self.__data[index] except IndexError as e: return e if __name__ == '__main__': s = Stack() s.push(34) s.push(59) s.push(21) print(s) print(s.pop()) s.push(45) print(s) print(s.pop()) print(s.pop()) print(s.pop()) print(s.pop()) s = stack([23, 45, 67]) print(s) print(s[2]) print(s[3])
def __init__(self): self._states = {} self._stack = stack([])
import collections from math import * stack = collections.stack() # FF: # general int is 256bit, aka -2**255 ... 2**256-1 # other type obey 256bit as an element # but also support bit 8, 16 and so on # for overflow it goes to 1 (wrap) def isAllReal(): # a symbolic or concolic pass # Symbolically executing an instruction def sym_exec_ins(params, block, instr, func_call, current_func_name): global MSIZE global visited_pcs global solver global vertices global edges global g_src_map global calls_affect_state global data_source stack = params.stack mem = params.mem memory = params.memory
def __init__(self): """ Initialize your data structure here. """ self.inbound = stack() self.outbound = stack()
from collections import stack a = stack()