-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathqueue.py
More file actions
44 lines (32 loc) · 765 Bytes
/
Copy pathqueue.py
File metadata and controls
44 lines (32 loc) · 765 Bytes
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
'''
队列
'''
class Queue(object):
# 初始化
def __init__(self):
self.__list = []
#添加元素
def push(self,element):
self.__list.append(element)
# 弹出元素
def pop(self):
if self.isEmpty():
return None
else:
return self.__list.pop(0)
#是否为空
def isEmpty(self):
return len(self.__list) == 0
def getSize(self):
return len(self.__list)
def __str__(self):
return " ".join(map(str, self.__list))
if __name__ == '__main__':
testQueue = Queue();
testQueue.push(1)
testQueue.push(2)
testQueue.push(3)
testQueue.push(4)
print(testQueue)
testQueue.pop()
print(testQueue)