[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

avi

1/4/2012 12:05:00 PM

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
3 Answers

Mayayana

1/4/2012 2:31:00 PM

0

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


avi

1/4/2012 5:46:00 PM

0

Thanks so much. It works perfectly but now I see that I need it
Descending and not Ascending

Could you help?

Thanks again
Avi

Jeff Johnson [MVP: VB]

1/4/2012 6:06:00 PM

0

"avi" <aviben@bezeqint.net.il> wrote in message
news:f0d2c18d-e08c-4dbc-a4c6-8005fb3ee859@p4g2000vbt.googlegroups.com...

> Thanks so much. It works perfectly but now I see that I need it
> Descending and not Ascending
>
> Could you help?

Seriously, you can't figure out the logic to reverse the sort direction?
Step through the code and see what it's doing. It should become obvious
after a couple of passes.