primo
30-08-2017, 18:20
can't use Array Sort in the following case (in which there is a one to one relation between numerical array and string array) so here is another approach
'---Load Console Module
Uses "Console"
Dim a(10) As Long
Dim names(10) As String
Long i, j, temp, flag
flag = 1
PrintL "---------- before descending sorting : --------"
Randomize
For i=1 To 10
a(i) = Rnd(1, 100)
names(i) = Chr$(64+i)
PrintL names(i)+" -- "+Str$(a(i))
Next
' sorting code
While flag = 1
flag = 0
For i=1 To 9
If a(i)<a(i+1) Then
flag = 1
Swap(a(i+1), a(i))
Swap(names(i+1), names(i))
End If
Next
If flag = 0 Then
Exit While
End If
Wend
PrintL "---------- after sorting : --------"
For i=1 To 10
PrintL names(i)+" -- "+Str$(a(i))
Next
PrintL "Press a key to end program"
'---Wait for a key press
WaitKey
'---Load Console Module
Uses "Console"
Dim a(10) As Long
Dim names(10) As String
Long i, j, temp, flag
flag = 1
PrintL "---------- before descending sorting : --------"
Randomize
For i=1 To 10
a(i) = Rnd(1, 100)
names(i) = Chr$(64+i)
PrintL names(i)+" -- "+Str$(a(i))
Next
' sorting code
While flag = 1
flag = 0
For i=1 To 9
If a(i)<a(i+1) Then
flag = 1
Swap(a(i+1), a(i))
Swap(names(i+1), names(i))
End If
Next
If flag = 0 Then
Exit While
End If
Wend
PrintL "---------- after sorting : --------"
For i=1 To 10
PrintL names(i)+" -- "+Str$(a(i))
Next
PrintL "Press a key to end program"
'---Wait for a key press
WaitKey