mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Add Zig code blocks.
This commit is contained in:
@@ -255,6 +255,12 @@ comments: true
|
||||
let isEmpty = stack.isEmpty
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="stack.zig"
|
||||
|
||||
```
|
||||
|
||||
## 5.1.2. 栈的实现
|
||||
|
||||
为了更加清晰地了解栈的运行机制,接下来我们来自己动手实现一个栈类。
|
||||
@@ -683,6 +689,12 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="linkedlist_stack.zig"
|
||||
|
||||
```
|
||||
|
||||
### 基于数组的实现
|
||||
|
||||
使用「数组」实现栈时,考虑将数组的尾部当作栈顶。这样设计下,「入栈」与「出栈」操作就对应在数组尾部「添加元素」与「删除元素」,时间复杂度都为 $O(1)$ 。
|
||||
@@ -1023,6 +1035,12 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="array_stack.zig"
|
||||
|
||||
```
|
||||
|
||||
## 5.1.3. 两种实现对比
|
||||
|
||||
### 支持操作
|
||||
|
||||
Reference in New Issue
Block a user