棧:python
# -*- 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()
隊列:app
# -*- 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()