-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQueue.py
38 lines (31 loc) · 1.19 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
#Queue ADT implementation in Python via a custom Queue Class.
class Queue:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def size(self):
return len(self.items)
def enqueue(self, item):
self.items.insert(0, item)
def dequeue(self):
#created an if and an elif statement to stop the errors of
#popping less than 0
if len(self.items) > 0:
return(self.items.pop())
elif len(self.items) == 0:
return None
#added defgetFront if the length is greater than one then the front would come out
#if it is less then none the front will return None
def getFront(self):
if len(self.items) > 0:
return self.items[len(self.items)-1]
elif len(self.items) == 0:
return None
#This is my string function! If amount of items in the list are greater than 0 then
#the item will be stringified if it is == to 0 then it will return an empty list.
def __str__(self):
if len(self.items) > 0:
return str(self.items)
elif len(self.items) == 0:
return str([])