BucketSort (really really fast)

Submitted on: 1/21/2015 6:33:00 PM
By: Rang3r (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages) , VBA MS Access, VBA MS Excel
Views: 658
     Sorts Integer Values really fast. on my 800mhz compu it sorts 100 000 values in 0.109 seconds...

Private Sub Form_Load()
 Dim MyArr(99999) As Long
 Dim i As Long
 Dim t As Variant
 For i = LBound(MyArr) To UBound(MyArr)
MyArr(i) = Rnd * 99999
 MsgBox "Click OK to start"
 t = Timer
 BucketSort MyArr
 MsgBox "READY!!!" & vbCrLf & "sorted 100000 values in " & Timer - t & " seconds"
 For i = LBound(MyArr) To UBound(MyArr)
List1.AddItem MyArr(i)
End Sub
Private Sub BucketSort(ByRef Arr() As Long)
 Dim Buckets(99999) As Long
 Dim i As Long
 Dim j As Long
 Dim pos As Long
 For i = LBound(Arr) To UBound(Arr)
Buckets(Arr(i)) = Buckets(Arr(i)) + 1
 pos = 0
 For i = LBound(Buckets) To UBound(Buckets)
Do While Buckets(i) > 0
 Arr(pos) = i
 Buckets(i) = Buckets(i) - 1
 pos = pos + 1
End Sub

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.