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

@ -293,7 +293,7 @@ comments: true
int size = deque.length;
/* 判断双向队列是否为空 */
bool isEmpty = deque.isEmpty;W
bool isEmpty = deque.isEmpty;
```
=== "Rust"
@ -337,6 +337,34 @@ comments: true
=== "Kotlin"
```kotlin title="deque.kt"
/* 初始化双向队列 */
val deque = LinkedList<Int>()
/* 元素入队 */
deque.offerLast(2) // 添加至队尾
deque.offerLast(5)
deque.offerLast(4)
deque.offerFirst(3) // 添加至队首
deque.offerFirst(1)
/* 访问元素 */
val peekFirst = deque.peekFirst() // 队首元素
val peekLast = deque.peekLast() // 队尾元素
/* 元素出队 */
val popFirst = deque.pollFirst() // 队首元素出队
val popLast = deque.pollLast() // 队尾元素出队
/* 获取双向队列的长度 */
val size = deque.size
/* 判断双向队列是否为空 */
val isEmpty = deque.isEmpty()
```
=== "Ruby"
```ruby title="deque.rb"
```
@ -1969,6 +1997,14 @@ comments: true
}
```
=== "Ruby"
```ruby title="linkedlist_deque.rb"
[class]{ListNode}-[func]{}
[class]{LinkedListDeque}-[func]{}
```
=== "Zig"
```zig title="linkedlist_deque.zig"
@ -2635,7 +2671,7 @@ comments: true
}
// 计算队尾指针,指向队尾索引 + 1
rear := q.index(q.front + q.queSize)
// 将 num 添加至队
// 将 num 添加至队
q.nums[rear] = num
q.queSize++
}
@ -3451,6 +3487,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="array_deque.rb"
[class]{ArrayDeque}-[func]{}
```
=== "Zig"
```zig title="array_deque.zig"

View File

@ -315,6 +315,32 @@ comments: true
=== "Kotlin"
```kotlin title="queue.kt"
/* 初始化队列 */
val queue = LinkedList<Int>()
/* 元素入队 */
queue.offer(1)
queue.offer(3)
queue.offer(2)
queue.offer(5)
queue.offer(4)
/* 访问队首元素 */
val peek = queue.peek()
/* 元素出队 */
val pop = queue.poll()
/* 获取队列的长度 */
val size = queue.size
/* 判断队列是否为空 */
val isEmpty = queue.isEmpty()
```
=== "Ruby"
```ruby title="queue.rb"
```
@ -1196,6 +1222,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="linkedlist_queue.rb"
[class]{LinkedListQueue}-[func]{}
```
=== "Zig"
```zig title="linkedlist_queue.zig"
@ -2176,6 +2208,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="array_queue.rb"
[class]{ArrayQueue}-[func]{}
```
=== "Zig"
```zig title="array_queue.zig"

View File

@ -309,6 +309,32 @@ comments: true
=== "Kotlin"
```kotlin title="stack.kt"
/* 初始化栈 */
val stack = Stack<Int>()
/* 元素入栈 */
stack.push(1)
stack.push(3)
stack.push(2)
stack.push(5)
stack.push(4)
/* 访问栈顶元素 */
val peek = stack.peek()
/* 元素出栈 */
val pop = stack.pop()
/* 获取栈的长度 */
val size = stack.size
/* 判断是否为空 */
val isEmpty = stack.isEmpty()
```
=== "Ruby"
```ruby title="stack.rb"
```
@ -1068,6 +1094,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="linkedlist_stack.rb"
[class]{LinkedListStack}-[func]{}
```
=== "Zig"
```zig title="linkedlist_stack.zig"
@ -1621,10 +1653,7 @@ comments: true
/* 出栈 */
fn pop(&mut self) -> Option<T> {
match self.stack.pop() {
Some(num) => Some(num),
None => None,
}
self.stack.pop()
}
/* 访问栈顶元素 */
@ -1745,6 +1774,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="array_stack.rb"
[class]{ArrayStack}-[func]{}
```
=== "Zig"
```zig title="array_stack.zig"