Guest User

Untitled

a guest
Jun 3rd, 2015
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. (define (RemoveElement element lst)
  2. ;if unique-left is applied to (list 1 4 2 1 5 4), the result would be (list 1 4 2 5)
  3. (cond
  4. [(empty? lst) empty]
  5. [(= element (first lst)) (RemoveElement element (rest lst))]
  6. [else (cons (first lst) (RemoveElement element (rest lst)))]))
  7.  
  8. (define (unique-left lst)
  9. (cond
  10. [(empty? lst) empty]
  11. [(member? (first lst) (rest lst)) (cons (first lst) (unique-left (RemoveElement (first lst) (rest lst))))]
  12. [else (cons (first lst) (unique-left (rest lst)))]
  13. )
  14. )
  15.  
  16. (define (unique-right lst)
  17. ;the result of applying it to (list 1 4 2 1 5 4) would be (list 2 1 5 4)
  18. (cond
  19. [(empty? lst) empty]
  20. [(not (member? (first lst) (rest lst))) (cons (first lst) (unique-right (rest lst)))]
  21. [else (unique-right (rest lst))]))
Advertisement
Add Comment
Please, Sign In to add comment