Name: Anonymous 2011-10-17 0:03
Hey guys I need help with my java coding. I'm required to write a code that takes 3 numbers (user input) and sort them from smallest to largest. Can someone show me how to code this?
(define sort3
(lambda (a b c)
(cond ((and (<= a b) (<= b c)) (list a b c))
((and (<= a c) (<= c b)) (list a c b))
((and (<= b a) (<= a c)) (list b a c))
((and (<= b c) (<= c a)) (list b c a))
((and (<= c a) (<= a b)) (list c a b))
((and (<= c b) (<= b a)) (list c b a)))))
(define run
(letrec ((n1 (read))
(n2 (read))
(n3 (read))
(r (sort3 n1 n2 n3)))
(map (lambda (x) (print x) (newline)) r)))
<= can take more than two arguments.(cond ((<= a b c) (list a b c))
((<= a c b) (list a c b))
...)