Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.56 KB | None | 0 0
  1.  
  2.  
  3. let lista1= [4;1;2;9;6;7;0;12;100];;
  4.  
  5.  
  6.  
  7. let rec max(unsorted, value) =
  8. match (unsorted, value) with
  9. ([],_) ->value|
  10. (v1::rest, _)-> if v1 > value
  11. then max(rest, v1)
  12. else max(rest, value);;
  13.  
  14.  
  15.  
  16. max(lista1, 0);;
  17.  
  18. let rec remove(l, x) =
  19. match l with
  20. []->[]|
  21. (h::t)->if h = x
  22. then t
  23. else h::remove(t, x);;
  24.  
  25. remove(lista1, 9);;
  26.  
  27. let rec sort(unsorted, sorted) =
  28. match unsorted with
  29. []->sorted|
  30. (v1::rest)->sort(remove(unsorted, max(rest, v1)), max(rest, v1)::sorted);;
  31.  
  32.  
  33.  
  34.  
  35.  
  36. let selectionSort(l) = sort(l, []);;
  37.  
  38.  
  39.  
  40. selectionSort(lista1);;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement