aboutsummaryrefslogtreecommitdiff
path: root/semestr-2/racket/solution.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'semestr-2/racket/solution.rkt')
-rw-r--r--semestr-2/racket/solution.rkt14
1 files changed, 14 insertions, 0 deletions
diff --git a/semestr-2/racket/solution.rkt b/semestr-2/racket/solution.rkt
new file mode 100644
index 0000000..3643668
--- /dev/null
+++ b/semestr-2/racket/solution.rkt
@@ -0,0 +1,14 @@
+#lang racket
+
+(provide heapsort) (require "leftist.rkt")
+
+(define (heapsort xs)
+ (define (create-heap xs res)
+ (if (null? xs)
+ res
+ (create-heap (cdr xs) (heap-insert (cons (car xs) (car xs)) res))))
+ (define (heap-to-list h)
+ (if (heap-empty? h)
+ null
+ (cons (elem-val (heap-min h)) (heap-to-list (heap-pop h)))))
+ (heap-to-list (create-heap xs empty-heap))) \ No newline at end of file