diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-04-19 13:29:04 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-04-19 13:29:04 -0400 |
| commit | 3b0dce04a08d864626f841383727fbdab339ec83 (patch) | |
| tree | c466e7104ff75c76394fd4796cb0752b4f2c6a13 /test | |
| parent | 072bd523b97aacaf8639dd89a49f0c1a16d1d405 (diff) | |
Add heapify(), heap_push(), and heap_pop()
Diffstat (limited to 'test')
| -rw-r--r-- | test/arrays.tm | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/arrays.tm b/test/arrays.tm index c8e34af4..be767fab 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -95,3 +95,22 @@ func main() = [30, 10, -20] >> ["A", "B", "C"]:sample(10, [1.0, 0.5, 0.0]) + + if yes + >> heap := [Int.random(max=50) for _ in 10] + >> heap:heapify() + >> heap + sorted := [:Int] + while #heap > 0 + sorted:insert(heap:heap_pop()) + >> sorted == sorted:sorted() + = yes + for _ in 10 + heap:heap_push(Int.random(max=50)) + >> heap + sorted = [:Int] + while #heap > 0 + sorted:insert(heap:heap_pop()) + >> sorted == sorted:sorted() + = yes + |
