;;class notes from for a binary tree. this is just an example of a binary tree, but I don't think it's applicable for this question. the example sort've helped me so I thought I'd post it (define-struct bst (ssn left right)) (make-ssn 312045678) (make-ssn 312012793) (make-ssn 312459012) (make-ssn 342147890) (define (merge alon1 alon2) (cond [(empty? alon1) alon2] [(empty? alon2) alon1] [(< (first alon1) (first alon2)) (cons (first alon1) (merge (rest alon1) alon2))] [else (cons (first alon2) (merge alon1 (rest alon2)))])) (define (make-singles l) (cond [(empty? l) '()] [else (cons (list (first l)) (make-singles (rest l)))])) (define (merge-neighbors alol) (cond [(empty? alol) '()] [(empty? (rest alol)) alol] [else (cons (merge (first alol) (second alol)) (merge-neighbors (cddr alol)))])) (define (merge-sort l) (cond [(empty? l) '()] [else (repeat-merge (make-singles l))])) (define (repeat-merge l) (cond [(empty? (rest l)) (first l)] [else (repeat-merge (merge-neighbors l))])) (check-expect (merge-sort '(5 3 4 9 2)) '(2 3 4 5 9))
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.