python模拟队列和堆栈(列表练习)
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,##################################queue##########################################!/usr/bin/env pytho
千家信息网最后更新 2025年12月01日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安全错误
数据库的锁怎样保障安全
计算机网络技术实训报告感悟
十大网络安全学校
天行加速器没有获得服务器地址
数据库教程推荐
安全的数据库客户端免费
云服务器基本防护
军工网络安全股有哪些
2b2t手游服务器地址
数据库中abcf是什么
怎样评价软件开发方法的优劣
c 转账存入数据库代码
如何基于某个软件开发新软件
上海核酸服务器
标准组态软件开发
金融行业用到的网络技术
服务器上文字出现问号乱码
安卓软件开发笔记本
网络安全周主题班会方案
我的世界网易修仙服务器2022
数据库工作引擎失败
长沙众元网络技术
企业网络安全应用中心下载
广州服务器电源哪个品牌好
网络安全的手抄报青少年
软件开发内幕
服务器哪家安全
java 数据库批量插入
广州珉人网络技术有限公司
吴忠软件开发网上价格
软件开发制作方案