博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python implement queue
阅读量:4030 次
发布时间:2019-05-24

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

用Python实现队列
2012-12-14              作者:buaa_shang
    
[python]  
#!/usr/bin/env python  
  
queue = []  
  
def enQ():  
    queue.append(raw_input('Enter new string: ').strip())  
  
#调用list的列表的pop()函数.pop(0)为列表的第一个元素  
def deQ():   www.2cto.com
    if len(queue) == 0:  
        print 'Cannot pop from an empty queue!'  
    else:  
        print 'Removed [', queue.pop(0) ,']'  
  
def viewQ():  
    print queue  
  
CMDs = {'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()  
这个程序与上一个 实现栈类似

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

你可能感兴趣的文章
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
终于搞定CString和string之间转换的问题了
查看>>
用防火墙自动拦截攻击IP
查看>>
补充自动屏蔽攻击ip
查看>>
谷歌走了
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>
Visual Studio 2010:C++0x新特性
查看>>
drwtsn32.exe和adplus.vbs进行dump文件抓取
查看>>
cppcheck c++静态代码检查
查看>>
在C++中使用Lua
查看>>
在Dll中调用自身的位图资源
查看>>
IP校验和详解
查看>>