Sorting algorithms/Sleep sort: Difference between revisions

m
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 FreeBASICfreebasic>' version 0521-0710-20152016
' 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 UIntegerULong)
Dim As IntegerLong lb = LBound(sleepy)
Dim As IntegerLong ub = UBound(sleepy)
Dim As IntegerLong i, count = ub
Dim As Double wakeup(lb To ub)
Dim As Double t = Timer
 
For i = lb To ub
wakeup(i) = sleepy(i) + 1 + t
Next
 
Line 486 ⟶ 487:
Print Using "####";sleepy(i);
wakeup(i) = 1e9 ' mark it as used
count = count - 1
End If
Next
Line 496 ⟶ 497:
' ------=< MAIN >=------
 
Dim As UIntegerULong i, arr(10)
Dim As UIntegerULong lb = LBound(arr)
Dim As UIntegerULong ub = UBound(arr)
 
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 InkeyInKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End</lang>
{{out}}
<pre>unsorted 15 12 25 16 94 16 49 45 41 72 20
 
sorted 10 1 12 12 24 25 45 45 46 76 9</pre>
 
=={{header|Go}}==
457

edits