Advertisement
Guest User

Untitled

a guest
Oct 13th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.96 KB | None | 0 0
  1. (define (small- lst)
  2.   (define (helper lst m)
  3.     (cond
  4.      ((and (null? (cdr lst))(< m (car lst))) m)
  5.      ((and (null? (cdr lst))(> m (car lst)))(car lst))
  6.      ((< m (car lst))(helper (cdr lst) m))
  7.      ((> m (car lst))(helper (cdr lst)(car lst)))))
  8.   (helper (cdr lst)(car lst)))
  9.  
  10. (define (remove- lst remove-me)
  11.   (cond
  12.    ((null? lst)'())
  13.    ((eq? (car lst) remove-me)(cdr lst))
  14.    (else
  15.     (cons (car lst)(remove- (cdr lst) remove-me)))))
  16.  
  17. (define (order- lst)
  18.   (cond
  19.    ((null? (cdr lst))(cons (car lst)'()))
  20.    (else
  21.     (let ((small (small- lst)))
  22.       (let ((remain (remove- lst small)))
  23.     (cons small (order- remain)))))))
  24.  
  25. (define (order- lst)
  26.   (define (helper lst final-lst)
  27.     (cond
  28.      ((null? (cdr lst))(cons (car lst) final-lst))
  29.      (else
  30.       (let ((small (small- lst)))
  31.     (let ((remain (remove- lst small)))
  32.       (helper remain (cons small final-lst)))))))
  33.   (helper (remove- lst (small- lst))(cons  (small- lst)'())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement