class Queue: """ Provides a rudimentary implementation of the queue data structure Attributes ---------- queue : (list of any) the underlying queue of objects Methods ------- is_empty(): (bool) returns whether the queue is empty add(item): (None) adds the item at the back of the queue remove(): (any) removes and returns the item from the front of the queue """ def __init__(self, initial_contents=[]): self.queue = initial_contents[:] def is_empty(self): """ returns whether the queue is empty :return: (bool) whether the queue is empty """ return self.queue == [] def add(self, item): """ adds the item at the back of the queue :param item: (any) the item to add at the back of the queue :return: (None) """ self.queue.append(item) def remove(self): """ removes and returns the item from the front of the queue :return: (any) the item from the front of the queue """ return self.queue.pop(0) def __str__(self): return "The queue contains: " + str(self.queue) def main(): q = Queue() print(q) q = Queue([1, 2, 3, 4]) print(q) q = Queue() q.add(1) q.add(10) q.add(2) print(q) q.remove() print(q) q.remove() print(q) q.remove() print(q) if __name__ == "__main__": main()