-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.py
68 lines (50 loc) · 1.29 KB
/
Queue.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# QUEUE IMPLEMENTATION
# DO NOT MODIFY
class Queue(object):
def __init__(self, list=None):
if list is None:
list = []
self.queue = list
# def get_list(self):
# return self.queue
def size(self):
return len(self.queue)
def front(self):
if self.is_empty():
return None
return self.queue[0]
def tail(self):
return self.queue[-1]
def deq(self):
if self.is_empty():
return None
return self.queue.pop(0)
def enq(self, data=None):
self.queue.append(data)
def print(self):
print(self.queue)
def __str__(self):
return self.queue.__str__()
def __repr__(self):
return self.queue.__repr__()
def is_empty(self):
return len(self.queue) == 0
def clear(self):
self.queue = []
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.queue == other.queue
return False
def main():
q = Queue()
q.print()
print("Is empty?", q.is_empty())
for i in range(1, 7):
q.enq(i)
print("Front: ", q.front())
print("Deq: ", q.deq())
q.print()
print("Is empty?", q.is_empty())
# Don't run main on import
if __name__ == "__main__":
main()