Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (swap-first-two lst)
- (let ((x (cond ((null? lst) '())
- ((null? (cdr lst)) lst)
- (else
- (list (car (cdr lst))
- (car lst))))))
- (cond ((null? lst) '())
- ((null? (cdr lst)) lst)
- (else
- (append x (cdr (cdr lst)))))))
- (swap-first-two '(1 2 3 4 5 6))
- (swap-first-two '(1))
- (swap-first-two '())
- (define (bubble-up lst)
- (if (null? lst)
- '()
- (cons (if (> (car lst)
- (car (cdr lst)))
- (car (swap-first-two lst))
- (car lst))
- (bubble-up (cdr lst)))))
- (bubble-up '(4 2 1 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement