Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. (* General function that checks if an int list is sorted *)
  2. fun issorted [] = true |
  3. issorted [x] = true |
  4. issorted (x::y::t) = x <= y andalso issorted(y::t);
  5.  
  6. (* Function that does the bubbling *)
  7. fun bubble [] = [] |
  8. bubble [x] = [x] |
  9. bubble (x::y::t) = if (x > y) then y::(bubble (x::t))
  10. else x::(bubble (y::t));
  11.  
  12. (* Call bubble on list until it is sorted *)
  13. fun bubbleSort [] = [] |
  14. bubbleSort l = if (issorted l) then l else bubbleSort (bubble l);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement