在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Python/ Python雙端隊列
Python樹遍歷算法
Python雙端隊列
Python隊列
Python回溯
Python棧
Python數(shù)據(jù)結(jié)構(gòu)開發(fā)環(huán)境
Python數(shù)據(jù)結(jié)構(gòu)簡介
Python算法分析
Python圖遍歷算法
Python搜索算法
Python圖
Python鏈表
Python集合
Python元組
Python字典
Python矩陣
Python高級鏈表(雙向鏈表)
Python搜索樹
Python二維數(shù)組
Python堆
Python節(jié)點
Python排序算法
Python數(shù)據(jù)結(jié)構(gòu)
Python遞歸
Python列表
Python數(shù)組
Python算法設(shè)計
Python哈希表

Python雙端隊列

雙端隊列(或兩端隊列)具有從任一端添加和刪除元素的功能。 Deque模塊是集合庫的一部分。 它具有添加和刪除可以直接用參數(shù)調(diào)用的元素的方法。 在下面的程序中,將導(dǎo)入collections模塊并聲明一個雙端隊列。 不需要任何類,直接使用內(nèi)置的實現(xiàn)這些方法。

參數(shù)以下代碼實現(xiàn) -

import collections
# Create a deque
DoubleEnded = collections.deque(["Mon","Tue","Wed"])
print (DoubleEnded)

# Append to the right
print("Adding to the right: ")
DoubleEnded.append("Thu")
print (DoubleEnded)

# append to the left
print("Adding to the left: ")
DoubleEnded.appendleft("Sun")
print (DoubleEnded)

# Remove from the right
print("Removing from the right: ")
DoubleEnded.pop()
print (DoubleEnded)

# Remove from the left
print("Removing from the left: ")
DoubleEnded.popleft()
print (DoubleEnded)

# Reverse the dequeue
print("Reversing the deque: ")
DoubleEnded.reverse()
print (DoubleEnded)

執(zhí)行上面示例代碼,得到以下結(jié)果 -

deque(['Mon', 'Tue', 'Wed'])
Adding to the right: 
deque(['Mon', 'Tue', 'Wed', 'Thu'])
Adding to the left: 
deque(['Sun', 'Mon', 'Tue', 'Wed', 'Thu'])
Removing from the right: 
deque(['Sun', 'Mon', 'Tue', 'Wed'])
Removing from the left: 
deque(['Mon', 'Tue', 'Wed'])
Reversing the deque: 
deque(['Wed', 'Tue', 'Mon'])

上一篇:Python數(shù)組下一篇:Python遞歸