ocaml: phase 5.1 binary_heap.ml baseline (min-heap sort 9 vals -> 123456789)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Array-backed binary min-heap with explicit size tracking via ref:
let push a size x =
a.(!size) <- x; size := !size + 1; sift_up a (!size - 1)
let pop a size =
let m = a.(0) in
size := !size - 1;
a.(0) <- a.(!size);
sift_down a !size 0;
m
Push [9;4;7;1;8;3;5;2;6], pop nine times -> 1,2,3,4,5,6,7,8,9.
Fold-as-decimal: ((((((((1*10+2)*10+3)*10+4)*10+5)*10+6)*10+7)*10+8)*10+9 = 123456789.
Tests recursive sift_up + sift_down, in-place array swap,
parent/lchild/rchild index arithmetic, combined push/pop session
with refs.
152 baseline programs total.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
"bf_full.ml": 6,
|
||||
"bisect.ml": 141,
|
||||
"bigint_add.ml": 28,
|
||||
"binary_heap.ml": 123456789,
|
||||
"bits.ml": 21,
|
||||
"balance.ml": 3,
|
||||
"base_n.ml": 17,
|
||||
|
||||
Reference in New Issue
Block a user