Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. (define (swap-first-two lst)
  2. (let ((x (cond ((null? lst) '())
  3. ((null? (cdr lst)) lst)
  4. (else
  5. (list (car (cdr lst))
  6. (car lst))))))
  7. (cond ((null? lst) '())
  8. ((null? (cdr lst)) lst)
  9. (else
  10. (append x (cdr (cdr lst)))))))
  11.  
  12.  
  13.  
  14. (swap-first-two '(1 2 3 4 5 6))
  15. (swap-first-two '(1))
  16. (swap-first-two '())
  17.  
  18. (define (bubble-up lst)
  19. (if (null? lst)
  20. '()
  21. (cons (if (> (car lst)
  22. (car (cdr lst)))
  23. (car (swap-first-two lst))
  24. (car lst))
  25. (bubble-up (cdr lst)))))
  26.  
  27. (bubble-up '(4 2 1 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement