I apologize, I know this is a Non-language specific forum, but I didn't know where else to post.
I was wondering if someone could help me to translate the following Scheme into an alternative pseudo-code...(like java or c)
I know that the following will insert a number, x, into a list, and the resulting list returned is a sorted list (in ascending order) with x included.
I have tried looking up each individual expression (like cond, cons, car, etc.) and while I get an idea of what it's supposed to do, I'm not getting the whole picture. If someone could help explain it to me, I'd appreciate it greatly!
(define insert (lambda (x myList) (cond ((null? myList) (cons x '())) ;base case (else (if (<= x (car myList)) (cons x myList) (cons (car myList) (insert x (cdr myList))))))))
//Example
> (insert 6 '(1 5 7))
(list 1 5 6 7)


Sign In
Create Account

Back to top









