Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. (defun p (X)
  2. (print X))
  3.  
  4. ;clen
  5.  
  6. (defun clen (X L)
  7. (cond ((null (car L)) NIL)
  8. ((= (car L) X) t)
  9. (t (clen X (cdr L)) )
  10.  
  11. ))
  12.  
  13. ;(p (clen 3 '(1 2 3 4 5 6 7)))
  14.  
  15.  
  16. ;clenx
  17. (defun clenx (X L)
  18. (cond ((null (car L)) NIL)
  19. ((= (car L) X) 1)
  20. (t (+ 1 (clenx X (cdr L))) )
  21.  
  22. ))
  23.  
  24. ;(p (clenx 7 '(1 2 3 4 5 6 7)))
  25.  
  26.  
  27. ;sort2----------------------------------------
  28.  
  29. ; find maximum item from list
  30. (defun max2 (L)
  31. (cond ((null (cdr L)) (car L))
  32. ((>= (car L) (cadr L)) (max2 (cons (car L)(delete (cadr L) L))) )
  33. (t (max2 (cons (cadr L)(delete (car L) L))) )
  34. ))
  35. ; deletes given item from list (only first occurance)
  36. (defun deleteOnce (X L)
  37. (cond ((= (car L) X) (cdr L) )
  38. (t (cons (car L) (deleteOnce X (cdr L)) ) )
  39. ))
  40.  
  41.  
  42. (defun sort2 (L)
  43. (cond ((null (cdr L)) L)
  44. (t (cons (max2 L) (sort2 (deleteOnce (max2 L) L)) ))
  45.  
  46. ))
  47.  
  48.  
  49. ;(p (sort2 '(1 2 5 4 8 7)))
  50. ;(p (sort2 '(1 1 5 6 )))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement