mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-02 18:20:58 +08:00
build
This commit is contained in:
@@ -296,7 +296,7 @@ comments: true
|
||||
|
||||
为了实现队列,我们需要一种数据结构,可以在一端添加元素,并在另一端删除元素。因此,链表和数组都可以用来实现队列。
|
||||
|
||||
### 基于链表的实现
|
||||
### 1. 基于链表的实现
|
||||
|
||||
对于链表实现,我们可以将链表的「头节点」和「尾节点」分别视为队首和队尾,规定队尾仅可添加节点,而队首仅可删除节点。
|
||||
|
||||
@@ -1181,7 +1181,7 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
### 基于数组的实现
|
||||
### 2. 基于数组的实现
|
||||
|
||||
由于数组删除首元素的时间复杂度为 $O(n)$ ,这会导致出队操作效率较低。然而,我们可以采用以下巧妙方法来避免这个问题。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user