栈:
# -*- coding: utf-8 -*- #定义序列 lst=[] def pop(): if(len(lst)==0): print"栈为空","无法出栈" else: print "此次出栈元素为:",lst.pop() def push(i): lst.append(i) push(1) push(2) push(3) pop() pop() pop() pop()
队列:
# -*- coding: utf-8 -*- lst=[] def enpush(i): lst.append(i) def enpop(): if(len(lst)==0): print "队列为空,无法出队" else: print"出队元素为:",lst.pop(0) enpush(10) enpush(20) enpush(2) enpop() enpop() enpop() enpop()