Mayayana
1/4/2012 2:31:00 PM
Here's almost exactly that in the form of VBScript. I
wrote it recently for a script designed to quickly
hunt for bloat on Windows that can be deleted. The script
generates a list of folders and their sizes, producing a
report file that lists all of that data, with the largest
folder at the top of the list.
This is a basic quicksort routine. It sorts the sizes
array and then sorts the folder paths array accordingly.
In other words, all you need to do is to add an extra
parameter to the quicksort routine, pointing to the
second array. Then add functionality in the routine to
do with arrayB whatever you do with arrayA.
NOTE: If you're sorting text you also need to consider
case. In VB, ">" can be applied to text for sorting, but A
is not equal to a. For alphabetic, non-case-sensitive
sorting you need to UCase of LCase both terms before
comparing.
'------------------------
'-- AIn1 is array to sort. AIn2 is array to match up to AIn1.
'-- LBeg, LEnd are array indices to start and end at. Use
'-- 0, 0. So: QuickSort A1, A2, 0, 0
Sub QuickSort(AIn1, AIn2, LBeg, LEnd)
Dim LBeg2, vMid, LEnd2, vSwap1, vSwap2
On Error Resume Next
If (LEnd = 0) Then LEnd = UBound(AIn1)
LBeg2 = LBeg
LEnd2 = LEnd
vMid = AIn1((LBeg + LEnd) \ 2)
Do
Do While AIn1(LBeg2) < vMid And LBeg2 < LEnd
LBeg2 = LBeg2 + 1
Loop
Do While vMid < AIn1(LEnd2) And LEnd2 > LBeg
LEnd2 = LEnd2 - 1
Loop
If LBeg2 <= LEnd2 Then
vSwap1 = AIn1(LBeg2)
vSwap2 = AIn2(LBeg2)
AIn1(LBeg2) = AIn1(LEnd2)
AIn2(LBeg2) = AIn2(LEnd2)
AIn1(LEnd2) = vSwap1
AIn2(LEnd2) = vSwap2
LBeg2 = LBeg2 + 1
LEnd2 = LEnd2 - 1
End If
Loop Until LBeg2 > LEnd2
If LBeg < LEnd2 Then QuickSort AIn1, AIn2, LBeg, LEnd2
If LBeg2 < LEnd Then QuickSort AIn1, AIn2, LBeg2, LEnd
End Sub
'------------------
--
--
"avi" <aviben@bezeqint.net.il> wrote in message
news:791c3771-7a1e-425e-af6f-0d33801c10c8@m20g2000vbf.googlegroups.com...
| Hello,
|
| I have 2 variant one dimensional arrays aaaa() and bbbb() of the same
| size
|
| I want to sort (ascending) aaaa() but want bbbb() to fit as before
| sorting. If for example aaaa(4) is now aaaa(10) after sorting, then
| bbbb(4) should become bbbb(10)
|
| Thanks a lot
| Avi