Ascending
arr=Array(460, 68, 2, 7, 3, 5, 1)
For i=ubound(arr)-1 to 0 step-1
For j=0 to i
If arr(j) >arr(j+1) Then
temp=arr(j+1)
arr(j+1)=arr(j)
arr(j)=temp
End If
Next
Next
'sorting an array in descending order
arr=Array(4, 6, 2, 7, 3, 5, 1)
For i=ubound(arr)-1 to 0 step-1
For j=0 to i
If arr(j)1) Then
temp=arr(j+1)
arr(j+1)=arr(j)
arr(j)=temp
End If
Next
Next
msgbox arr(0)
msgbox arr(1)
msgbox arr(2)
msgbox arr(3)
msgbox arr(4)
msgbox arr(5)
msgbox arr(6)
arr=Array(460, 68, 2, 7, 3, 5, 1)
For i=ubound(arr)-1 to 0 step-1
For j=0 to i
If arr(j) >arr(j+1) Then
temp=arr(j+1)
arr(j+1)=arr(j)
arr(j)=temp
End If
Next
Next
'sorting an array in descending order
arr=Array(4, 6, 2, 7, 3, 5, 1)
For i=ubound(arr)-1 to 0 step-1
For j=0 to i
If arr(j)
temp=arr(j+1)
arr(j+1)=arr(j)
arr(j)=temp
End If
Next
Next
msgbox arr(0)
msgbox arr(1)
msgbox arr(2)
msgbox arr(3)
msgbox arr(4)
msgbox arr(5)
msgbox arr(6)
No comments:
Post a Comment