This commit is contained in:
krahets
2024-03-31 03:53:04 +08:00
parent 87af663929
commit c23e576da4
68 changed files with 2139 additions and 22 deletions

View File

@ -1968,6 +1968,14 @@ The implementation code is as follows:
}
```
=== "Ruby"
```ruby title="linkedlist_deque.rb"
[class]{ListNode}-[func]{}
[class]{LinkedListDeque}-[func]{}
```
=== "Zig"
```zig title="linkedlist_deque.zig"
@ -2634,7 +2642,7 @@ The implementation only needs to add methods for "front enqueue" and "rear deque
}
// 计算队尾指针,指向队尾索引 + 1
rear := q.index(q.front + q.queSize)
// 将 num 添加至队
// 将 num 添加至队
q.nums[rear] = num
q.queSize++
}
@ -3450,6 +3458,12 @@ The implementation only needs to add methods for "front enqueue" and "rear deque
}
```
=== "Ruby"
```ruby title="array_deque.rb"
[class]{ArrayDeque}-[func]{}
```
=== "Zig"
```zig title="array_deque.zig"

View File

@ -1196,6 +1196,12 @@ Below is the code for implementing a queue using a linked list:
}
```
=== "Ruby"
```ruby title="linkedlist_queue.rb"
[class]{LinkedListQueue}-[func]{}
```
=== "Zig"
```zig title="linkedlist_queue.zig"
@ -2176,6 +2182,12 @@ In a circular array, `front` or `rear` needs to loop back to the start of the ar
}
```
=== "Ruby"
```ruby title="array_queue.rb"
[class]{ArrayQueue}-[func]{}
```
=== "Zig"
```zig title="array_queue.zig"

View File

@ -1068,6 +1068,12 @@ Below is an example code for implementing a stack based on a linked list:
}
```
=== "Ruby"
```ruby title="linkedlist_stack.rb"
[class]{LinkedListStack}-[func]{}
```
=== "Zig"
```zig title="linkedlist_stack.zig"
@ -1621,10 +1627,7 @@ Since the elements to be pushed onto the stack may continuously increase, we can
/* 出栈 */
fn pop(&mut self) -> Option<T> {
match self.stack.pop() {
Some(num) => Some(num),
None => None,
}
self.stack.pop()
}
/* 访问栈顶元素 */
@ -1745,6 +1748,12 @@ Since the elements to be pushed onto the stack may continuously increase, we can
}
```
=== "Ruby"
```ruby title="array_stack.rb"
[class]{ArrayStack}-[func]{}
```
=== "Zig"
```zig title="array_stack.zig"