Results 1 to 7 of 7

Thread: Sorting an Array

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 1999
    Posts
    34
    Hi, if I have an array of say 50 numbers.

    how do I get the Biggest Number, Smallest number and
    sort them into assending or desending order

    thanks

    MICK

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Go look at this thread.
    You should search the forum before asking a question,
    just a tip

  3. #3

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

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

    ___ Adolf Jensen

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    There are a lot of ways to sort an array. The bubble sort is the easiest. It's also the slowest. But if the arrays aren't too big, speed doesn't really matter. To do a bubble sort:
    Code:
        Dim List(1 To 5) As String 'the array
        Dim Swap As String 'temporary
        Dim I As Integer 'for loops
        Dim J As Integer 'for loops
        
        List(1) = "Hello"
        List(2) = "Bye"
        List(3) = "Lala"
        List(4) = "Blabla"
        List(5) = "Kaboom"
        
        'sort them
        For I = 1 To UBound(List)
            'the bubble sort moves large values to the top
            For J = 1 To UBound(List) - 1
                'compare them
                If List(J) > List(J + 1) Then
                    'list(x)>list(x+1)
                    Swap = List(J + 1)
                    List(J + 1) = List(J)
                    List(J) = Swap
                End If
            Next
        Next
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Oetje :
    Alpha and numeric are different sorts. My post, the one above yours on this thread, demonstates a numeric bubble sort....if interested.

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

    ___ Adolf Jensen

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Good code HeSaidJoe, but you should comment it.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

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