Changes

Data Sorting in VB6

1,583 bytes added, 16:45, 29 January 2008
The following lines were added (+) and removed (-):
Countingsort does not use comparisons.  The items to sort must be integers, and this sort works best with a limited or defined range.  A range across 1000 will work well, a range across 100,000 will not.  <nowiki>Sub Countingsort (List() As Long, sorted_list() As Long, _</nowiki>  <nowiki>    min As Integer, max As Integer, min_value As Long, _</nowiki>  <nowiki>    max_value As Long)</nowiki>  <nowiki>Dim counts() As Integer</nowiki>  <nowiki>Dim i As Integer</nowiki>  <nowiki>Dim this_count As Integer</nowiki>  <nowiki>Dim next_offset As Integer</nowiki>  <nowiki></nowiki>  <nowiki>    ' Create the Counts array.</nowiki>  <nowiki>    ReDim counts(min_value To max_value)</nowiki>  <nowiki></nowiki>  <nowiki>    ' Count the items.</nowiki>  <nowiki>    For i = min To max</nowiki>  <nowiki>        counts(List(i)) = counts(List(i)) + 1</nowiki>  <nowiki>    Next i</nowiki>  <nowiki></nowiki>  <nowiki>    ' Convert the counts into offsets.</nowiki>  <nowiki>    next_offset = min</nowiki>  <nowiki>    For i = min_value To max_value</nowiki>  <nowiki>        this_count = counts(i)</nowiki>  <nowiki>        counts(i) = next_offset</nowiki>  <nowiki>        next_offset = next_offset + this_count</nowiki>  <nowiki>    Next i</nowiki>  <nowiki></nowiki>  <nowiki>    ' Place the items in the sorted array.</nowiki>  <nowiki>    For i = min To max</nowiki>  <nowiki>        sorted_list(counts(List(i))) = List(i)</nowiki>  <nowiki>        counts(List(i)) = counts(List(i)) + 1</nowiki>  <nowiki>    Next i</nowiki>  <nowiki>End Sub</nowiki>
Bureaucrat, administrator
16,192
edits