aboutsummaryrefslogtreecommitdiff
path: root/Semestr 2/racket/solution.rkt
blob: 3643668454c9053b99a3e21a8d66e6858b315c38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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)))