Results 1 to 6 of 6

Thread: alphbetical sort

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,092

    Cool

    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?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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:\ADirtBagDogWebSite
    C:\Ati
    C:\betacorp
    etc
    etc
    etc
    c:\Z Mp3 Files
    C:\ab
    C:\abc
    C:\audio
    C:\cdRipper
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    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. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

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



Click Here to Expand Forum to Full Width