mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-12 15:36:05 +00:00
build
This commit is contained in:
@@ -410,19 +410,19 @@ comments: true
|
||||
|
||||
如圖 5-8 所示,我們將雙向鏈結串列的頭節點和尾節點視為雙向佇列的佇列首和佇列尾,同時實現在兩端新增和刪除節點的功能。
|
||||
|
||||
=== "LinkedListDeque"
|
||||
=== "<1>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push_last()"
|
||||
=== "<2>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push_first()"
|
||||
=== "<3>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop_last()"
|
||||
=== "<4>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop_first()"
|
||||
=== "<5>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> 圖 5-8 基於鏈結串列實現雙向佇列的入列出列操作 </p>
|
||||
@@ -2158,19 +2158,19 @@ comments: true
|
||||
|
||||
如圖 5-9 所示,與基於陣列實現佇列類似,我們也可以使用環形陣列來實現雙向佇列。
|
||||
|
||||
=== "ArrayDeque"
|
||||
=== "<1>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push_last()"
|
||||
=== "<2>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push_first()"
|
||||
=== "<3>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop_last()"
|
||||
=== "<4>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop_first()"
|
||||
=== "<5>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> 圖 5-9 基於陣列實現雙向佇列的入列出列操作 </p>
|
||||
|
||||
@@ -379,13 +379,13 @@ comments: true
|
||||
|
||||
如圖 5-5 所示,我們可以將鏈結串列的“頭節點”和“尾節點”分別視為“佇列首”和“佇列尾”,規定佇列尾僅可新增節點,佇列首僅可刪除節點。
|
||||
|
||||
=== "LinkedListQueue"
|
||||
=== "<1>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push()"
|
||||
=== "<2>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop()"
|
||||
=== "<3>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> 圖 5-5 基於鏈結串列實現佇列的入列出列操作 </p>
|
||||
@@ -1329,13 +1329,13 @@ comments: true
|
||||
|
||||
可以看到,入列和出列操作都只需進行一次操作,時間複雜度均為 $O(1)$ 。
|
||||
|
||||
=== "ArrayQueue"
|
||||
=== "<1>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push()"
|
||||
=== "<2>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop()"
|
||||
=== "<3>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> 圖 5-6 基於陣列實現佇列的入列出列操作 </p>
|
||||
@@ -2072,7 +2072,7 @@ comments: true
|
||||
typedef struct {
|
||||
int *nums; // 用於儲存佇列元素的陣列
|
||||
int front; // 佇列首指標,指向佇列首元素
|
||||
int queSize; // 尾指標,指向佇列尾 + 1
|
||||
int queSize; // 當前佇列的元素數量
|
||||
int queCapacity; // 佇列容量
|
||||
} ArrayQueue;
|
||||
|
||||
|
||||
@@ -376,13 +376,13 @@ comments: true
|
||||
|
||||
如圖 5-2 所示,對於入堆疊操作,我們只需將元素插入鏈結串列頭部,這種節點插入方法被稱為“頭插法”。而對於出堆疊操作,只需將頭節點從鏈結串列中刪除即可。
|
||||
|
||||
=== "LinkedListStack"
|
||||
=== "<1>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push()"
|
||||
=== "<2>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop()"
|
||||
=== "<3>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> 圖 5-2 基於鏈結串列實現堆疊的入堆疊出堆疊操作 </p>
|
||||
@@ -1169,13 +1169,13 @@ comments: true
|
||||
|
||||
使用陣列實現堆疊時,我們可以將陣列的尾部作為堆疊頂。如圖 5-3 所示,入堆疊與出堆疊操作分別對應在陣列尾部新增元素與刪除元素,時間複雜度都為 $O(1)$ 。
|
||||
|
||||
=== "ArrayStack"
|
||||
=== "<1>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "push()"
|
||||
=== "<2>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
=== "pop()"
|
||||
=== "<3>"
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> 圖 5-3 基於陣列實現堆疊的入堆疊出堆疊操作 </p>
|
||||
|
||||
Reference in New Issue
Block a user