class Queue: def __init__(self): self.size = 0 self.storage = LinkedList() def __len__(self): return self.size def enqueue(self, value): # self.storage.append(value) self.storage.add_to_tail(value) self.size += 1 def dequeue(self): if self.size == 0: return None self.size -= 1 return self.storage.remove_head()
class Stack: def __init__(self): self.size = 0 # self.storage = [] self.storage = LinkedList() def __len__(self): return self.size def push(self, value): # self.storage.append(value) #adding values to the list self.size += 1 #incrementing size so when we ask for lenth we get the correct answer self.storage.add_to_tail(value) def pop(self): if self.size == 0: return None self.size -= 1 return self.storage.remove_tail()
class Queue: def __init__(self): self.size = 0 self.storage = LinkedList() def __len__(self): return self.size def enqueue(self, value): self.size += 1 return self.storage.add_to_tail(value) def dequeue(self): if self.size > 0: self.size -= 1 return self.storage.remove_head() def len(self): return len(self.storage)