class Queue: """ Queue using Circular Double Linked List """ def __init__(self): self.queue = LinkedList() self.is_full = False self.is_empty = True def __len__(self): return len(self.queue) def enqueue(self, key, data=None): """ add an item to the queue :param key: key to add :param data: new node data """ self.queue.insert_end(key, data) def dequeue(self): """ remove an item from the queue :return: item key """ node = self.queue.fild_last_node() self.queue.remove_beginning() if self.queue.head is None: self.is_empty = True else: self.is_empty = False if node is None: return None return node.key def peek(self): """ gets the element at the front of the queue without removing it :return: item key """ node = self.queue.head if node is None: return None return node.key
def test_remove_beginning(self): """ test remove_beginning() """ # test on empty linked list list1 = LinkedList() list1.remove_beginning() # generate linked list nums = 10 list1, reference_arr = generate_filled_list(LinkedList, nums) # remove from beginning list1.remove_beginning() list_arr = list(list1) # compare results to reference reference_arr = reference_arr[1:] self.assertEqual(list_arr, reference_arr)