diff options
Diffstat (limited to 'Semestr 2/racket/solution.rkt')
-rw-r--r-- | Semestr 2/racket/solution.rkt | 14 |
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 |