-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueList.py
49 lines (38 loc) · 1.11 KB
/
QueueList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
from DCList import DCList
class QueueList(DCList):
""" QueueList Class
"""
def __init__(self):
""" Constructor
Calls init from DCList
"""
DCList.__init__(self)
def push(self, data):
""" Push an object onto the QueueList
:param data: object to push
"""
self.insertBefore(data)
def pop(self):
""" Pops an object from the QueueList
:return: The top object on the QueueList
"""
head_data = self.peek()
self.remove()
return head_data
def peek(self):
""" Shows the top element of the QueueList, without removing it.
:return: Top object on the QueueList
"""
if self.head is None:
raise IndexError("Empty QueueList")
return self.head.data
def purge(self):
""" Remove all elements from the QueueList
"""
self.__init__()#tret el self de dins()
def __len__(self):
""" Overload.
:return: The number of elements in the QueueList
"""
return self.length