这个在官网中list支持,有实现。补充一下栈,队列的特性:
1.栈(stacks)是一种只能通过访问其一端来实现数据存储与检索的线性数据结构,具有后进先出(last in first out,LIFO)的特征
2.队列(queue)是一种具有先进先出特征的线性数据结构,元素的增加只能在一端进行,元素的删除只能在另一端进行。能够增加元素的队列一端称为队尾,可以删除元素的队列一端则称为队首。
地址在 http://docs.python.org/2/tutorial/datastructures.html#more-on-lists ,下面的官方的代码。
关于栈
>>> stack = ["wolf", "wulaoer", "吴老二"] >>> stack.append("wulaoer.org") >>> stack.append("www.wulaoer.org") >>> stack ["wolf", "wulaoer", "吴老二", "wulaoer.org", "www.wulaoer.org"] >>> stack.pop() www.wulaoer.org >>> stack ["wolf", "wulaoer", "吴老二","wulaoer.org"] >>> stack.pop() "wulaoer.org" >>> stack.pop() "吴老二" >>> stack [“wolf”, "wulaoer"]
关于队列
>>> from collections import deque >>> queue = deque(["Eric", "John", "Michael"]) >>> queue.append("wulaoer.org") # wulaoer.org arrives >>> queue.append("www.wulaoer.org") # www.wulaoer.org arrives >>> queue.popleft() # The first to arrive now leaves 'Eric' >>> queue.popleft() # The second to arrive now leaves 'John' >>> queue # Remaining queue in order of arrival deque(['Michael', 'wulaoer.org', 'www.wulaoer.org'])
上面代码很清晰的解释了上面的2种结构
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏