|
-
Jan 29th, 2002, 02:40 PM
#1
Thread Starter
Hyperactive Member
QuickSort
I got the QuickSort code from somewhere??
here is a quick example.
VB Code:
Private Type Descriptions
strDesc As String
strCode As String
End Type
Private Sub Quicksort(ByRef p_Array() As Descriptions, ByVal inLow As Long, ByVal inHi As Long)
'A version of the QuickSort Algorithm applied to the User Defined Data Type "Descriptions"
Dim pivot As Descriptions
Dim tmpSwap As Descriptions
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = p_Array((inLow + inHi) \ 2)
While (tmpLow <= tmpHi)
While (p_Array(tmpLow).strDesc < pivot.strDesc And tmpLow < inHi)
tmpLow = tmpLow + 1
Wend
While (pivot.strDesc < p_Array(tmpHi).strDesc And tmpHi > inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
tmpSwap = p_Array(tmpLow)
p_Array(tmpLow) = p_Array(tmpHi)
p_Array(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow < tmpHi) Then Quicksort p_Array, inLow, tmpHi
If (tmpLow < inHi) Then Quicksort p_Array, tmpLow, inHi
End Sub
-
Jun 10th, 2009, 11:35 AM
#2
New Member
Re: Array sorting for user-defined data types
An interesting piece of code...
The last 2 lines puzzle me, since they it seems like a circular reference
to sub Quicksort, namely
If (inLow < tmpHi) Then Quicksort p_Array, inLow, tmpHi
If (tmpLow < inHi) Then Quicksort p_Array, tmpLow, inHi
Also, can you provide a fuller sample code with the end result being a sorted
array Descriptions().
-
Jun 10th, 2009, 04:30 PM
#3
Re: Array sorting for user-defined data types
The last 2 lines puzzle me, since they it seems like a circular reference
that is correct it is a recursive procedure the array is not sorted in one pass so the sub is continuously called until fully sorted
there is several examples in code bank that may contain more information
@OP is there a question, or is it all working correctly?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|