Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.6) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
4 ;A list-of-numbers is either
5 ;1. an empty list or
6 ;2. (cons n lon)
7 ;where n is a number and lon is a list-of-numbers.
8 ;
9 ;sortascend : list-of-numbers -> list-of-numbers
10 ;Given a-lon, sorts a-lon in ascending order.
12 (define (sortascend a-lon)
13 (local ((define (sort a-lon)
14 (cond
15 [(empty? a-lon) empty]
16 [(cons? a-lon) (insert (first a-lon) (sort (rest a-lon)))]))
17 (define (insert a-number a-lon)
18 (cond
19 [(empty? a-lon) (list a-number)]
20 [(<= a-number (first a-lon)) (cons a-number a-lon)]
21 [else (cons (first a-lon) (insert a-number (rest a-lon)))])))
22 (sort a-lon)))