1 Star 0 Fork 0

zoey/python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
queue.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
zoey 提交于 2016-06-03 23:04 +08:00 . add stack.py queue.py and change the readme file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'把列表用做队列:列队的特点为先入先出(FIFO)。'
queue = []
# 添加元素
def enQ():
queue.append(raw_input(' 输入新的字符: ').strip())
# 出队列
def deQ():
if len(queue) == 0:
print '不能从空的队列中移除元素'
else:
print '移除 [', `queue.pop(0)`, ']'
# 查看
def viewQ():
print('目前列队为:'),
print(queue)
CMDs = {'e':enQ, 'd':deQ, 'v':viewQ}
# 显示菜单
def showmenu():
pr = '''
(E)nqueue
(D)equeue
(V)iew
(Q)uit
输入你的选择(e:入列队/d:出列队/v:查看列队/q:退出):'''
while True:
while True:
try:
choice = raw_input(pr).strip()[0].lower()
except (EOFError,KeyboardInterrupt,IndexError):
choice = 'q'
print '\n你选择的操作是: [%s]' % choice
if choice not in 'edvq':
print ('无效输入,请按要求重新输入')
else:
break
if choice == 'q':
print('感谢您的使用,编程愉快!')
break
CMDs[choice]()
if __name__ == '__main__':
showmenu()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zoeywoohoo/python.git
git@gitee.com:zoeywoohoo/python.git
zoeywoohoo
python
python
master

搜索帮助