Skip to content

Commit a704c0d

Browse files
authored
feat: finalize ruby code transpilation (krahets#1379)
1 parent a14be17 commit a704c0d

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

docs/chapter_heap/heap.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,31 @@
122122
Queue<Integer> minHeap = new PriorityQueue<>();
123123
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
124124
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
125-
125+
126126
/* 元素入堆 */
127127
maxHeap.offer(1);
128128
maxHeap.offer(3);
129129
maxHeap.offer(2);
130130
maxHeap.offer(5);
131131
maxHeap.offer(4);
132-
132+
133133
/* 获取堆顶元素 */
134134
int peek = maxHeap.peek(); // 5
135-
135+
136136
/* 堆顶元素出堆 */
137137
// 出堆元素会形成一个从大到小的序列
138138
peek = maxHeap.poll(); // 5
139139
peek = maxHeap.poll(); // 4
140140
peek = maxHeap.poll(); // 3
141141
peek = maxHeap.poll(); // 2
142142
peek = maxHeap.poll(); // 1
143-
143+
144144
/* 获取堆大小 */
145145
int size = maxHeap.size();
146-
146+
147147
/* 判断堆是否为空 */
148148
boolean isEmpty = maxHeap.isEmpty();
149-
149+
150150
/* 输入列表并建堆 */
151151
minHeap = new PriorityQueue<>(Arrays.asList(1, 3, 2, 5, 4));
152152
```
@@ -337,7 +337,7 @@
337337
max_heap.push(2);
338338
max_heap.push(5);
339339
max_heap.push(4);
340-
340+
341341
/* 获取堆顶元素 */
342342
let peek = max_heap.peek().unwrap(); // 5
343343

@@ -373,39 +373,39 @@
373373
var minHeap = PriorityQueue<Int>()
374374
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
375375
val maxHeap = PriorityQueue { a: Int, b: Int -> b - a }
376-
376+
377377
/* 元素入堆 */
378378
maxHeap.offer(1)
379379
maxHeap.offer(3)
380380
maxHeap.offer(2)
381381
maxHeap.offer(5)
382382
maxHeap.offer(4)
383-
383+
384384
/* 获取堆顶元素 */
385385
var peek = maxHeap.peek() // 5
386-
386+
387387
/* 堆顶元素出堆 */
388388
// 出堆元素会形成一个从大到小的序列
389389
peek = maxHeap.poll() // 5
390390
peek = maxHeap.poll() // 4
391391
peek = maxHeap.poll() // 3
392392
peek = maxHeap.poll() // 2
393393
peek = maxHeap.poll() // 1
394-
394+
395395
/* 获取堆大小 */
396396
val size = maxHeap.size
397-
397+
398398
/* 判断堆是否为空 */
399399
val isEmpty = maxHeap.isEmpty()
400-
400+
401401
/* 输入列表并建堆 */
402402
minHeap = PriorityQueue(mutableListOf(1, 3, 2, 5, 4))
403403
```
404404

405405
=== "Ruby"
406406

407407
```ruby title="heap.rb"
408-
408+
# Ruby 未提供内置 Heap 类
409409
```
410410

411411
=== "Zig"

0 commit comments

Comments
 (0)