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 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 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 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 self.size -= 1 self.storage.remove_head() # Queue first in first out
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 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): 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 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.__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 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.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 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()
class Stack: 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 push(self, value): if not self.storage.head: self.storage.head = Node(value) self.storage.tail = Node(value) else: self.storage.head = Node(value, self.storage.head) def pop(self): return self.storage.remove_head()
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 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()