-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathqueue.py
More file actions
66 lines (51 loc) · 1.25 KB
/
queue.py
File metadata and controls
66 lines (51 loc) · 1.25 KB
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
66
#!/usr/bin/env python
# coding:utf-8
'''
欢迎参加黄哥python远程视频培训,
帮你完成从不会写代码到会写代码解决问题的过渡。
https://github.com/pythonpeixun/article/blob/master/index.md
咨询qq:1465376564
黄哥Python培训 黄哥改写
Python 3
P148页代码
'''
queue = []
def enQ():
queue.append(input('Enter new queue element: '))
def deQ():
if len(queue) == 0:
print('Cannot dequeue from empty queue!')
else:
print('Removed [', queue.pop(0), ']')
def viewQ():
print(str(queue))
def showmenu():
prompt = """
(E)nqueue
(D)equeue
(V)iew
(Q)uit
Enter choice: """
done = 0
while not done:
chosen = 0
while not chosen:
try:
choice = input(prompt)[0]
except (IndexError, EOFError, KeyboardInterrupt):
choice = 'q'
print('\nYou picked: [%s]' % choice)
if choice not in 'devq':
print('invalid option, try again')
else:
chosen = 1
if choice == 'q':
done = 1
if choice == 'e':
enQ()
if choice == 'd':
deQ()
if choice == 'v':
viewQ()
if __name__ == '__main__':
showmenu()