Re: VB6 LISTBOX problem
- From: "Steve Gerrard" <mynamehere@xxxxxxxxxxx>
- Date: Sat, 20 Oct 2007 21:40:02 -0700
inline...
"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message
news:uY05Je4EIHA.3980@xxxxxxxxxxxxxxxxxxxxxxx
Not very quick on my machine (733 MHz). It took about 12
seconds. Here's a QuickSort method that pulls the data out
of your array, sorts it, then puts the sorted data back into your
array, in under 2 seconds....
Well under 1 sec on my 21st century box. :)
' Pull the data out
Sorted = String((UB - LB + 1) * 6, "*")
ofs = 1
For idx = LB To UB
Mid(Sorted, ofs, 1) = MyType(idx).AString1
Mid(Sorted, ofs + 1, 4) = Format$(MyType(idx).ANum, "0000")
Mid(Sorted, ofs + 5, 1) = MyType(idx).AString2
ofs = ofs + 6
Next
I love this concept. It would not have occurred to me to build a single string
representing the entire array, but as each element is a fixed length, it makes
perfect sense. The notion of then sorting the 6 char elements of the single
string is excellent, and avoids the noise of 47,000 separate string allocations.
If up <= dn Then
If up < dn Then
temp = Mid$(Sorted, dn, 6)
Mid(Sorted, dn, 6) = Mid$(Sorted, up, 6)
Mid(Sorted, up, 6) = temp
End If
up = up + 6
dn = dn - 6
End If
Others may not care, but it has always bothered me that many implementations of
the quick sort do not put the additional test "If up < dn" around the swap.
Allowing it to swap when up = dn just seems wrong to me, and I'm glad to see
some one else cares enough to give their very best. :)
.
- Follow-Ups:
- Re: VB6 LISTBOX problem
- From: Randy Birch
- Re: VB6 LISTBOX problem
- References:
- VB6 LISTBOX problem
- From: xx3884@xxxxxxxxxxxxxx
- Re: VB6 LISTBOX problem
- From: mayayana
- Re: VB6 LISTBOX problem
- From: Richard Mueller [MVP]
- Re: VB6 LISTBOX problem
- From: xx3884@xxxxxxxxxxxxxx
- Re: VB6 LISTBOX problem
- From: Larry Serflaten
- VB6 LISTBOX problem
- Prev by Date: Re: Displaying Recycle bin true contents in ListView
- Next by Date: Re: Calculate Last Digits
- Previous by thread: Re: VB6 LISTBOX problem
- Next by thread: Re: VB6 LISTBOX problem
- Index(es):
Relevant Pages
|