From 3b0dce04a08d864626f841383727fbdab339ec83 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 19 Apr 2024 13:29:04 -0400 Subject: Add heapify(), heap_push(), and heap_pop() --- test/arrays.tm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') 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 + -- cgit v1.2.3