博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用Python实现队列
阅读量:2350 次
发布时间:2019-05-10

本文共 919 字,大约阅读时间需要 3 分钟。

#!/usr/bin/env pythonqueue = []def enQ():    queue.append(raw_input('Enter new string: ').strip())#调用list的列表的pop()函数.pop(0)为列表的第一个元素def deQ():    if len(queue) == 0:        print 'Cannot pop from an empty queue!'    else:        print 'Removed [', queue.pop(0) ,']'def viewQ():    print queueCMDs = {'e': enQ, 'd': deQ, 'v': viewQ}def showmenu():    pr = """    (E)nqueue    (D)equeue    (V)iew    (Q)uit        Enter choice: """    while True:        while True:            try:                choice = raw_input(pr).strip()[0].lower()            except (EOFError, KeyboardInterrupt, IndexError):                choice = 'q'            print '\nYou picked: [%s]' % choice            if choice not in 'devq':                print 'Invalid option, try again'            else:                break        if choice == 'q':            break        CMDs[choice]()if __name__ == '__main__':    showmenu()
这个程序与上一个Python实现栈类似

转载地址:http://wihvb.baihongyu.com/

你可能感兴趣的文章
Elasticsearch 7.x生产配置
查看>>
AccessDeniedException: /opt/elasticsearch-7.0.0/config/elasticsearch.keystore
查看>>
bootstrap-table 父子表 联动表 完整例子
查看>>
Spring Cloud 2.x完整入门Demo样例(Greenwich版本)
查看>>
Spring Cloud 2.x学习笔记:2、feign改进(Greenwich版本)
查看>>
SpringCloud 2.x学习笔记:3、Hystrix(Greenwich版本)
查看>>
SpringCloud 2.x学习笔记:4、Zuul(Greenwich版本)
查看>>
ajax提交JSON数组及Springboot接收转换为list类
查看>>
SpringCloud 2.x学习笔记:5、Config(Greenwich版本)
查看>>
RabbitMQ安装、配置与入门
查看>>
Ibatis代码自动生成工具
查看>>
ant build.xml教程详解
查看>>
彻底理解ThreadLocal
查看>>
STM32 HAL库、标准外设库、LL库(STM32 Embedded Software)
查看>>
基于STM32CubeMX创建STM32L496ZGTx的工程
查看>>
如何通过OpenFace实现人脸识别框架
查看>>
Angle和XBGoost以及Spark的性能对比
查看>>
Node.js & Electron的扩展模块
查看>>
Mysql semi-sync VS group replication, 谁快?
查看>>
碎片清理
查看>>