Sorting algorithms/Sleep sort: Difference between revisions
m
→{{header|FreeBASIC}}: minor change
m (→{{header|FreeBASIC}}: removed redundant code) |
m (→{{header|FreeBASIC}}: minor change) |
||
Line 464:
Can't use FreeBASIC '''sleep''' since it halts the program.
Instead it uses a second array filled with times based on the value of number, this array is check against the timer. If the timer is past the stored time the value is printed.
<lang
' compile with: fbc -s console
' compile with: fbc -s console -exx (for bondry check on the array's)
' not very well suited for large numbers and large array's
' positive numbers only
Sub sandman(sleepy() As
Dim As
Dim As
Dim As
Dim As Double wakeup(lb To ub)
Dim As Double t = Timer
For i = lb To ub
wakeup(i) = sleepy(i) +
Next
Line 486 ⟶ 487:
Print Using "####";sleepy(i);
wakeup(i) = 1e9 ' mark it as used
count = count -
End If
Next
Line 496 ⟶ 497:
' ------=< MAIN >=------
Dim As
Dim As
Dim As
Randomize Timer
For i = lb To ub -1 ' leave last one zero
arr(i) = Int(Rnd * 10) +1
Next
Line 517 ⟶ 518:
' empty keyboard buffer
While
Print : Print "hit any key to end program"
Sleep
End</lang>
{{out}}
<pre>unsorted
sorted
=={{header|Go}}==
|