Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import composit.lang.*
  2.  
  3. decl [mergesort -> list
  4. ([list sortme])
  5.  
  6. decl [merge -> list ; synonymous with '-> {}'
  7. ([lists list one, list two])
  8. if lists.one == {} ret [lists.two]
  9. if lists.two == {} ret [lists.one]
  10.  
  11. let x = [take 1 lists.one] ; -> {} with size 1
  12. let y = [take 1 lists.two] ; -> {} with size 1
  13. ret [x > y ? y + [merge [x + [drop 1 lists.one], lists.one]]
  14. : x + [merge [lists.one, y + [drop 1 lists.two]]]
  15. ]
  16. ]
  17.  
  18. decl [split -> [list, list]
  19. ([list splitme])
  20. let si = splitme.length / 2 ; split index
  21. ret [[take si splitme], [drop si splitme]]
  22. ]
  23.  
  24. let [decl [list left, list right]] sides = [split sortme]
  25. if sortme.length > 1 ret [merge [[mergesort sides.left], [mergesort sides.right]]]
  26. else ret sortme
  27. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement