1. okay, I found a code by Razzle at here , but I looked at it and my brain almost caught fire.
Could somebody dumb it down for me?

2. I think there's a lot easier way to sort the array.
Code:
```Sub SortArray(p_Array)
Dim i As Integer
Dim j As Integer
Dim varTemp As Variant

For i = UBound(p_Array) To LBound(p_Array) Step -1
For j = LBound(p_Array) + 1 To i
If p_Array(j - 1) > p_Array(j) Then
varTemp = p_Array(j - 1)
p_Array(j - 1) = p_Array(j)
p_Array(j) = varTemp
End If
Next
Next
End Sub```

3. ## <?>

Serge:

Any idea why this is sort like so.
I used my bubble sort and yours and both give me this
as a sort of my directories under C:\

I would think that C:\ab should be the second folder listed
and that C:\abc would be next, yet they come after Z

C:\A New Tip Holder
C:\Ati
C:\betacorp
etc
etc
etc
c:\Z Mp3 Files
C:\ab
C:\abc
C:\audio
C:\cdRipper

4. That's because uppercase 'Z' is smaller than lowercase 'a', to be more precise 'Z' has number 90 in the ASCII table, while 'a' has number 97 (try using UCase function to convert everything to uppercase before you sort it)

[Edited by QWERTY on 11-05-2000 at 07:34 PM]

5. ## <?>

QWERTY

Thanks...
Option Compare Text does the job for me.

Can't believe I missed that. Time to shut down and
pay attention to my drink.

Later

6. Well it's called shellsort, and one of the fastest nonrecursive sorting algoritms, so it's not usual ppl don't understand a thing of it. WEll i've been wasting my brain on it anyway:
Code:
```Sub Sort_shell(a() As String)
Dim n&, i&, j&, k&, h

n = UBound(a)
k = n \ 2 'k interval is greatest at first
While k > 0
For i = 0 To n - k 'loop from start to the middle of the list then 3/4 then 7/8... to be optimal if you compare to the interval
j = i
While (j >= 0) And (a(j) > a(j + k)) 'compare items from withing smaller and smaller intervals from within the loop the first value to the last
h = a(j) 'swap items if in wrong order
a(j) = a(j + k)
a(j + k) = h
If j > k Then 'the inner pointer j will decrement k (less every loop) and be set to 0 in case to avoid subscipt out of range
j = j - k
Else
j = 0
End If
Wend 'This goes on until the inner pointer is 0
Next i
k = k \ 2
Wend
End Sub```
Loop 1: Goes trough smaller and smaller (n/x) intervals
Loop 2: Goes trough the each item and compares items with the distance that is getting smaller
Loop 3: Decremeanting the inner pointer each interval until it hits 0 while it swaps items that aren't in order.

It took me a while to understand why it does the third, but well here's an example:
Code:
```1 2 3 4 5 6 7 8 9 10 11 12

^     ^     ^     ^```
if k is 3 then it will compare each third item starting from the first item and going to ward the last items then sending an item on the wrong place backwards to the right point by decreasing j by k all the time. Now these are done with the highest k first then k getting smaller until it's 0 so items movement are done optimally, at least thats how i understood it.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•