Results 1 to 38 of 38

Thread: [RESOLVED] sorting arrays

Threaded View

  1. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: sorting arrays

    Here is code that sorts arrays: havent tried it with numbers but it should work..

    Make a copy of the random array.. sort the copy..
    then compare Sorted to original.. creating an array with the index order?
    sounds like it might work... but, there is probably a better way lol
    sort code:

    VB Code:
    1. 'Author: CVMichael
    2. 'Thread: [url]http://www.vbforums.com/showthread.php?t=231925[/url]
    3.  
    4. Private Sub QuickSort(C() As String, ByVal First As Long, ByVal Last As Long)
    5.     Dim Low As Long, High As Long
    6.     Dim MidValue As String
    7.    
    8.     Low = First
    9.     High = Last
    10.     MidValue = C((First + Last) \ 2)
    11.    
    12.     Do
    13.     While C(Low) < MidValue
    14.     Low = Low + 1
    15.     Wend
    16.    
    17.     While C(High) > MidValue
    18.     High = High - 1
    19.     Wend
    20.    
    21.     If Low <= High Then
    22.         Swap C(Low), C(High)
    23.         Low = Low + 1
    24.         High = High - 1
    25.     End If
    26. Loop While Low <= High
    27.  
    28. If First < High Then QuickSort C, First, High
    29. If Low < Last Then QuickSort C, Low, Last
    30. End Sub
    31.  
    32. Private Sub Swap(ByRef A As String, ByRef B As String)
    33.     Dim T As String
    34.    
    35.     T = A
    36.     A = B
    37.     B = T
    38. End Sub
    Last edited by Static; Nov 29th, 2005 at 01:11 PM.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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