CODIGO FONTE ALGORITMO QUICKSORT URGENTE!
Eu estou procurando o código fonte do algoritmo de QuickSort. Se der pra alguem me ajudar eu agradeço.
Grato
Demetrius
Grato
Demetrius
Na falta de um exemplo...
'Algoritimo QuickSort
Public Sub QuickSort(vSort As Variant, Optional ByVal lngStart As Variant, Optional ByVal lngEnd As Variant)
If IsMissing(lngStart) Then lngStart = LBound(vSort)
If IsMissing(lngEnd) Then lngEnd = UBound(vSort)
Dim i As Long
Dim j As Long
Dim h As Variant
Dim x As Variant
i = lngStart: j = lngEnd
x = vSort((lngStart + lngEnd) / 2)
' Array aufteilen
Do
While (vSort(i) x): i = i + 1: Wend
While (vSort(j) x): j = j - 1: Wend
If (i = j) Then
h = vSort(i)
vSort(i) = vSort(j)
vSort(j) = h
i = i + 1: j = j - 1
End If
Loop Until (i j)
If (lngStart j) Then QuickSort vSort, lngStart, j
If (i lngEnd) Then QuickSort vSort, i, lngEnd
End Sub
E agora outro, do VBNet, que basicamente é A MESMA COISA.
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub QuickSortVariants(vArray As Variant, inLow As Long, inHi As Long)
Dim pivot As Variant
Dim tmpSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
While (tmpLow = tmpHi)
While (vArray(tmpLow) pivot And tmpLow inHi)
tmpLow = tmpLow + 1
Wend
While (pivot vArray(tmpHi) And tmpHi inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow = tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow tmpHi) Then QuickSortVariants vArray, inLow, tmpHi
If (tmpLow inHi) Then QuickSortVariants vArray, tmpLow, inHi
End Sub
'Algoritimo QuickSort
Public Sub QuickSort(vSort As Variant, Optional ByVal lngStart As Variant, Optional ByVal lngEnd As Variant)
If IsMissing(lngStart) Then lngStart = LBound(vSort)
If IsMissing(lngEnd) Then lngEnd = UBound(vSort)
Dim i As Long
Dim j As Long
Dim h As Variant
Dim x As Variant
i = lngStart: j = lngEnd
x = vSort((lngStart + lngEnd) / 2)
' Array aufteilen
Do
While (vSort(i) x): i = i + 1: Wend
While (vSort(j) x): j = j - 1: Wend
If (i = j) Then
h = vSort(i)
vSort(i) = vSort(j)
vSort(j) = h
i = i + 1: j = j - 1
End If
Loop Until (i j)
If (lngStart j) Then QuickSort vSort, lngStart, j
If (i lngEnd) Then QuickSort vSort, i, lngEnd
End Sub
E agora outro, do VBNet, que basicamente é A MESMA COISA.
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub QuickSortVariants(vArray As Variant, inLow As Long, inHi As Long)
Dim pivot As Variant
Dim tmpSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
While (tmpLow = tmpHi)
While (vArray(tmpLow) pivot And tmpLow inHi)
tmpLow = tmpLow + 1
Wend
While (pivot vArray(tmpHi) And tmpHi inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow = tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow tmpHi) Then QuickSortVariants vArray, inLow, tmpHi
If (tmpLow inHi) Then QuickSortVariants vArray, tmpLow, inHi
End Sub
Tópico encerrado , respostas não são mais permitidas