Advertisement
linesguy

Bubble sort visualised

Jan 28th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. 1 num(1) = 150 : rem how many arrays (1-279)
  2. 2 num(2) = 150 : rem max height of array (1-191)
  3. 3 seed = 10 : rem seed used for random num generator
  4.  
  5. 9 for s = 1 to seed : q = rnd(1) : next
  6. 10 hgr2 : dim X(280) : hcolor = 3
  7. 20 for x = 0 to num(1)
  8. 30 X(X) = 191 - int(rnd(1)*num(2)) : hplot X,191 to X,X(X)
  9. 40 next
  10. 45 Z = num(1)-1
  11.  
  12. 50 for x = 0 to Z
  13. 60 if X(X)<X(X+1) then gosub 1000
  14. 70 next
  15. 80 Z = Z - 1 : if z <> 0 then goto 50
  16. 90 for x = 0 to num(1)
  17. 100 hcolor = 1 : hplot X,191 to X,X(X)
  18. 110 next
  19.  
  20.  
  21.  
  22. 999 end
  23. 1000 hcolor = 0 : hplot X,191 to X,X(X) to X+1,191 to X+1,X(X+1)
  24. 1010 S = X(X) : X(X) = X(X+1) : X(X+1) = S
  25. 1020 hcolor = 3 : hplot X,191 to X,X(X) : hplot X+1,191 to X+1,X(X+1)
  26. 1030 return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement