- Python 資料結構與演算法教程
- Python - 資料結構主頁
- Python - 資料結構簡介
- Python - 資料結構環境
- Python - 陣列
- Python - 列表
- Python - 元組
- Python - 字典
- Python - 二維陣列
- Python - 矩陣
- Python - 集合
- Python - 對映
- Python - 連結串列
- Python - 堆疊
- Python - 佇列
- Python - 雙端佇列
- Python - 高階連結串列
- Python - 雜湊表
- Python - 二叉樹
- Python - 搜尋樹
- Python - 堆
- Python - 圖
- Python - 演算法設計
- Python - 分治
- Python - 遞迴
- Python - 回溯
- Python - 演算法排序
- Python - 演算法搜尋
- Python - 圖演算法
- Python - 演算法分析
- Python - 大 O 符號
- Python - 演算法類
- Python - 折舊分析
- Python - 演算法證明
- Python 資料結構與演算法實用資源
- Python - 快速指南
- Python - 實用資源
- Python - 討論
Python - 雙端佇列
雙端佇列或佇列支援從任一端新增和移除元素。更常用的堆疊和佇列是佇列的簡化形式,其中輸入和輸出限制為一端。
示例
import collections
DoubleEnded = collections.deque(["Mon","Tue","Wed"])
DoubleEnded.append("Thu")
print ("Appended at right - ")
print (DoubleEnded)
DoubleEnded.appendleft("Sun")
print ("Appended at right at left is - ")
print (DoubleEnded)
DoubleEnded.pop()
print ("Deleting from right - ")
print (DoubleEnded)
DoubleEnded.popleft()
print ("Deleting from left - ")
print (DoubleEnded)
輸出
當執行上述程式碼時,它會生成以下結果 -
Appended at right - deque(['Mon', 'Tue', 'Wed', 'Thu']) Appended at right at left is - deque(['Sun', 'Mon', 'Tue', 'Wed', 'Thu']) Deleting from right - deque(['Sun', 'Mon', 'Tue', 'Wed']) Deleting from left - deque(['Mon', 'Tue', 'Wed'])
廣告