雙端佇列(deque,全名double-ended queue)是一種具有佇列堆疊性質的抽象資料類型。雙端佇列中的元素可以從兩端彈出,插入和刪除操作限定在佇列的兩邊進行。

操作

雙端佇列可以在佇列任意一端入隊出隊。此外,經常還會有一個檢視(Peek)操作,返回該端的資料而不將其出隊。

操作的名稱依語言的不同而不同;主流實現包括:

More information 操作, 常見名稱 ...
操作 常見名稱 Ada C++ Java Perl PHP Python Ruby JavaScript
尾部插入 inject, snoc Append push_back offerLast push array_push append push push
頭部插入 push, cons Prepend push_front offerFirst unshift array_unshift appendleft unshift unshift
尾部刪除 eject Delete_Last pop_back pollLast pop array_pop pop pop pop
頭部刪除 pop Delete_First pop_front pollFirst shift array_shift popleft shift shift
檢視尾部 Last_Element back peekLast $array[-1] end <obj>[-1] last <obj>[<obj>.length - 1]
檢視頭部 First_Element front peekFirst $array[0] reset <obj>[0] first <obj>[0]
Close

外部連結

Wikiwand in your browser!

Seamless Wikipedia browsing. On steroids.

Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.

Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.