HELP! Does anyone know anything about scheme

Status
Not open for further replies.

LauraP

Solid State Member
Messages
14
Could some PLEASE take a look at this I am stuck and I need this figured by mignight TONIGHT. This is all I could come up with.

Given a list you take the first element (5) off the list then you compare it to everything in the list and make a small list and a big list everything in the list less then 5 goes in small list and everything greater goes in big list then you have to sort them and place 5 at the beginning of the big list and concatenate (append) the two list together.

(define quicksort (list ))
(define ls '(5 7 3 1 8 6))
(cond
(( ) )
**I have to come up with some stop condition here**


(define small (x l))
(cond
((null? l) 0)
((> x (car l)) (cons (car l)(small (cdr l))
(else (small(cdr l) ))

(define big (x l))
(cond
((null? l) 0)
((< x (car l)) (cons(car l)(big (cdr l))
(else (small (cdr l) ))

(append (quicksort (small car ls) (cdr ls))))
(cons (car ls) (quicksort (big (car ls) (cdr ls))))
 
So you were basically implementing a quicksort algorithm in scheme?


Nice job, scheme isn't the nicest language in the world to work with linked lists.
 
Status
Not open for further replies.
Back
Top Bottom