class Queue: def __init__(self): self.storage = LinkedList() self.size = 0 def __len__(self): return self.size def enqueue(self, value): # Easiest solution is to use linked list tail to enqueue self.size += 1 self.storage.add_to_tail(value) # # # use linked list tail to enqueue # self.storage.add_to_head(value) def dequeue(self): # # use linked list tail to dequeue # if self.size ==0: # return None # self.size -=1 # value_dequeue = self.storage.remove_tail() # return value_dequeue # here is a easier solution: dequeue from head: if self.size == 0: return None self.size -= 1 value_dequeue = self.storage.remove_head() return value_dequeue
class Stack: def __init__(self): self.storage = LinkedList() def __len__(self): return self.storage.length def push(self, value): self.storage.add_to_tail(value) def pop(self): if self.storage.length == 0: return None return self.storage.remove_tail()
class Queue: def __init__(self): self.size = 0 self.storage = LinkedList() def __len__(self): return len(self.storage) def enqueue(self, value): self.storage.add_to_tail(value) def dequeue(self): return self.storage.remove_head()
class Queue: def __init__(self): self.__storage = LinkedList() def __len__(self): return self.length @property def length(self): return len(self.__storage) def enqueue(self, value): self.__storage.add_to_tail(value) def dequeue(self): return self.__storage.remove_head()
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 >= 1: self.size -= 1 return self.storage.remove_head() else: return None # ex = Queue() # # ex.enqueue(39) # ex.enqueue(3) # ex.enqueue(6) # # print(ex.__len__()) # print(ex.storage.get_max()) # # ex.dequeue() # # print(ex.__len__()) # print(ex.storage.get_max())
class Stack: def __init__(self): self.size = 0 self.storage = LinkedList() def __len__(self): return self.size def push(self, value): self.storage.add_to_tail(value) self.size += 1 def pop(self): if self.size == 0: return None self.size -= 1 return self.storage.remove_tail()
class LinkedListQueue: def __init__(self): self.size = 0 self.storage = LinkedList() def __len__(self): return self.size def enqueue(self, value): self.size += 1 self.storage.add_to_tail(value) 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 = LinkedList() def __len__(self): return len(self.storage) def __str__(self): return str(self.storage) def push(self, value): self.storage.add_to_tail(value) def pop(self): if len(self.storage) > 0: return self.storage.remove_tail()
class Queue: def __init__(self): self.storage = LinkedList() def __len__(self): return self.storage.length def enqueue(self, value): try: self.storage.add_to_tail(value) except: return None def dequeue(self): try: prev_head = self.storage.remove_head() return prev_head except: return None
class Queue: def __init__(self): self.size = 0 self.storage = LinkedList( ) #singly_linked_list.LinkedList() is what I had before that made this work def __len__(self): return self.size def enqueue(self, value): self.storage.add_to_tail(value) self.size += 1 return self.storage def dequeue(self): data = self.storage.remove_head() if self.size != 0: self.size -= 1 return data
class Queue: def __init__(self): self.__storage = LinkedList() def __len__(self): return self.length @property def length(self): return len(self.__storage) def enqueue(self, value): # print(f"Q: enqueueing value '{value}' to queue") self.__storage.add_to_tail(value) def dequeue(self): output = self.__storage.remove_head() # print(f"Q: dequeueing value '{output}' from queue") return output
class LinkedListStack: def __init__(self): self.size = 0 self.storage = LinkedList() # len returns the number of elements in the stack. def __len__(self): return self.size # push adds an item to the top of the stack. def push(self, value): self.storage.add_to_tail(value) self.size += 1 # pop removes and returns the element at the top of the stack 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): count = 0 current_node = self.storage.head while current_node is not None: count = count + 1 current_node = current_node.next_node return count def enqueue(self, value): self.storage.add_to_tail(value) def dequeue(self): return self.storage.remove_head()
class Queue: def __init__(self): self.storage = LinkedList() def __len__(self): s = self.storage.length # print(f"Size: {s}") return s def enqueue(self, value): # print(f"Enqueue: {value}") self.storage.add_to_tail(value) # print(f"Size: {self.storage.length}") def dequeue(self): if self.storage.length == 0: return None # print(f"Value: {self.storage.head.get_value()}") v = self.storage.head.get_value() self.storage.remove_head() return v
class Queue: def __init__(self): self.size = 0 # Store Data through invocation of the LinkedList self.storage = LinkedList() def __len__(self): # Returning the tracked size of the Linked list return self.size def enqueue(self, value): # Add to size as adding items self.size += 1 # add item to the tail through LinkedList methods self.storage.add_to_tail(value) def dequeue(self): # Establish empty size of List if self.storage.head == None: self.size = 0 else: # Subtract as removing items self.size -= 1 return self.storage.remove_head()
class Stack: def __init__(self): self.size = 0 self.storage = LinkedList() self.head = None self.tail = None def __len__(self): return self.size def push(self, value): # size of LL gets increased by 1 every time we push self.size += 1 return self.storage.add_to_tail(value) def pop(self): # check if LL is empty. If so, we cannot remove an element if self.size == 0: return None # if not empty, remove the tail (LIFO) and decrase the size by 1 else: self.size -= 1 return self.storage.remove_tail()
class Queue: def __init__(self): self.size = 0 self.storage = LinkedList() self.front = None self.rear = None def __len__(self): return self.size def enqueue(self, value): # add element to LL's tail and incrase size by 1 self.size += 1 return self.storage.add_to_tail(value) def dequeue(self): # if LL is empty, do nothing if self.size == 0: return None # if LL is not empty, decrease size by 1 and remove head (FIFO) else: self.size -= 1 return self.storage.remove_head()