python模拟队列和堆栈(列表练习)
发表于:2025-02-24 作者:千家信息网编辑
千家信息网最后更新 2025年02月24日,##################################queue##########################################!/usr/bin/env pytho
千家信息网最后更新 2025年02月24日python模拟队列和堆栈(列表练习)
##################################queue##########################################!/usr/bin/env python'use list as a queue'#define a void list as a void queuequeue = []#define in queue functiondef enQ(): queue.append(raw_input('Enter New String: ').strip())#define out queue functiondef deQ(): #judge queue whether viod if len(queue) == 0: print('Can not pop from an empty queue!') else: print('Removed' ,queue.pop(0))#define show queue functiondef viewQ(): print(queue)#define a dictionary to chose opration functioncmds = {'e':enQ,'d':deQ,'v':viewQ}#define a funtion to show menudef showMenu(): pr = ''' (E)nqueue (D)equeue (V)iew (Q)uit Enter choice:''' #double while circle make program always run while True: while True: try: #use to print menu information and get valid choice number(no space, just one bit , lower) choice = raw_input(pr).strip()[0].lower() except(EOFError,KeyboardInterrupt,IndexError): #if get a invalid value,return 'q' choice = 'q' print('You picked: %s '% choice) if choice not in 'devq': print('Invalid option, try again!') else: break if choice == 'q': break #call functions by dictionary cmds[choice]()#main functionif __name__ == '__main__': showMenu() ##################################stack###################################### #!/usr/bin/env python'this program use list as a stack'stack = []def pushit(): 'input stack ' stack.append(raw_input('Enter New Strings: ').strip())def popit(): 'output stack' if len(stack) == 0: print('Can not pop from an empty stack!') else: print('removed [',stack.pop(),']')def viewStack(): print(stack)CMDs = {'u': pushit, 'o': popit, 'v': viewStack}def showMenu(): pr = ''' p(U)sh p(O)p (V)iew (Q)uit Enter Choice: ''' while True: while True: try: choice = raw_input(pr).strip()[0].lower() print(choice) except(EOFError.KeyboardInterrupt,IndexError): choice = 'q' print('you picked: %s ' % choice) if choice not in 'uovq': print('Invalid option, try again') else: break if choice == 'q': break CMDs[choice]()if __name__ == '__main__': showMenu()
堆栈
队列
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
福建工业软件开发市场报价
小白科技互联网公司电话
数据库安全现状
网络安全巡警编程设计开发书籍
网鼎杯网络安全大赛攻略
北京亿速云服务器虚拟主机
随申办服务器炸了
服务器文件不可用
共享文件只读服务器就没有响应
海北州软件开发成交价
神武服务器等级多少开60级武器
怎么看待计算机网络技术这个专业
网络安全知识竞赛有一等奖吗
幼儿园网络安全和信息化
工会网络安全宣传内容
洛阳火速网络技术有限公司怎么样
软件开发商合同范本
上海游驰网络技术 电话
转回原服务器能带多少多少
网络安全信息安全学科所学专业
虚拟服务器vpn
软件开发总包协议
软件开发创业计划书ppt
数据库oracle面试
数据库查询记录为空的语句
cc数据库设计图
火灾报警系统软件开发
中职计算机网络技术面试试讲
网络安全法维护哪些权益
express 服务器