Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* General function that checks if an int list is sorted *)
- fun issorted [] = true |
- issorted [x] = true |
- issorted (x::y::t) = x <= y andalso issorted(y::t);
- (* Function that does the bubbling *)
- fun bubble [] = [] |
- bubble [x] = [x] |
- bubble (x::y::t) = if (x > y) then y::(bubble (x::t))
- else x::(bubble (y::t));
- (* Call bubble on list until it is sorted *)
- fun bubbleSort [] = [] |
- bubbleSort l = if (issorted l) then l else bubbleSort (bubble l);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement