Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with sorting array

Status
Not open for further replies.

sara123

Programmer
Jun 14, 2004
3
US
hello ive only just started learning visual basics but i am finding arrays a bit hard my proble is that i have ten randomized numbers and i need to sort them into numeric order i thank you for any help at all .
 
Ten items? Bubble sort.
# compares = (N*N+N) / 2: 10=55: 100=5050: 1000 = 500,500
Not good for arrays with many items.
Code:
Dim I as long
Dim J as long
Dim K as long
Dim L as long
Dim M as long
Dim array(10) as long
K = Ubound(array)
' Minimizes swaps
For I = Lbound(array) to  K - 1
    M = array(I)
    For J = I + 1 To K   'Find the least of I and the rest
        If M > array(J) then
            array(I) = array(J)
            array(J) = M
            M = array(I)
        end if
    Next
Next
 
thank you for your help but im sorry im still confused with it
 
Thank you that helped me alot to understand arrays better thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top