MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / LinkedQueue

Class LinkedQueue

linked_lists/linked_queue.py:5–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3 pass
4
5class LinkedQueue:
6
7 class _Node:
8 __slots__ = ("_element", "_next")
9
10 def __init__(self, element, next_):
11 self._element = element
12 self._next = next_
13
14 def __init__(self):
15 self._head = None
16 self._size = 0
17 self._tail = None
18
19 def is_empty(self):
20 return self._size == 0
21
22
23 def enqueue(self, element):
24 new_tail = self._Node(element, None)
25 if self.is_empty():
26 self._head = new_tail
27 else:
28 self._tail._next = new_tail
29 self._tail = new_tail
30 self._size += 1
31
32 def dequeue(self):
33 if self.is_empty():
34 raise Empty("Queue is empty")
35 target = self._head._element
36 self._head = self._head._next
37 self._size -= 1
38
39 return target

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected