class Stack: def __init__(self): self.size = 0 self.storage = LinkedList() def __len__(self): return self.size def push(self, value): self.size += 1 self.storage.add_to_head(value) def pop(self): self.size -= 1 self.storage.remove_tail()
class Stack: def __init__(self): self.__storage = LinkedList() def __len__(self): return self.size def push(self, value): self.__storage.add_to_head(value) def pop(self): return self.__storage.remove_head() @property def size(self) -> int: return len(self.__storage)
class Stack: def __init__(self): self.storage = LinkedList() def __len__(self): return len(self.storage) def push(self, value): self.storage.add_to_head(value) def pop(self): try: removed = self.storage.remove_head() return removed except: return None
class Stack: def __init__(self, size=0): self.size = size self.storage = LinkedList() def __len__(self): return self.size def push(self, value): self.size += 1 # current.storage.add_to_tail(key) self.storage.add_to_head(value) # print(current.storage.head.key) def pop(self): if self.size == 0: return self.size -= 1 # return current.storage.remove_tail() # print(current.storage.head.key) return self.storage.remove_head()