Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. use "random"
  2. use "collections"
  3. use "itertools"
  4.  
  5. actor Main
  6. let env: Env
  7. let hands: Array[USize]
  8.  
  9. new create (env': Env) =>
  10. env = env'
  11. env.out.print("Creating array ...")
  12. let size: USize = 260_000
  13. hands = Iter[USize](Range(0, size)).collect(Array[USize](size))
  14. Rand.shuffle[USize](hands)
  15. try
  16. for i in Range(0,5) do
  17. env.out.print(hands(i)?.string())
  18. end
  19. end
  20.  
  21. env.out.print("Starting insertion sort ...")
  22. do_sort()
  23.  
  24. be do_sort() =>
  25. env.out.flush()
  26. try
  27. for i in Range(1, hands.size()) do
  28. let item = hands(i)?
  29. var j = i
  30. while (j > 0) and (hands(j - 1)? > item) do
  31. hands(j)? = hands(j - 1)?
  32. j = j - 1
  33. end
  34. hands(j)? = item
  35. end
  36. end
  37.  
  38. env.out.print("Complete.")
  39. try
  40. for i in Range(0,5) do
  41. env.out.print(hands(i)?.string())
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement