fb:porticula NoPaste
Shakersort-Beispiel
Uploader: | The_Muh |
Datum/Zeit: | 23.06.2010 20:02:58 |
declare Sub ShakerSort(feld() As Integer)
randomize timer
dim values(10) as integer
for i as integer = 1 to 10
values(i) = rnd(1)*100+1
? values(i)
next
? "---"
ShakerSort(values())
for i as integer = 1 to 10
? values(i)
next
'Quelle:
'http://de.wikipedia.org/wiki/Cocktailsort#Visual_Basic
'nur leicht angepasst.
Sub ShakerSort(feld() As Integer)
Dim Size As Integer
Dim Half As Integer
Dim Temp As Integer
Dim As Integer I, J
Size = UBound(Feld) + 1 'Größe des Arrays +1
Half = Size / 2
For I = 1 To Half
For J = 1 To UBound(Feld) - I 'aufwärts
If Feld(J) > Feld(J + 1) Then
Temp = Feld(J)
Feld(J) = Feld(J + 1)
Feld(J + 1) = Temp
End If
Next J
For J = UBound(Feld) To 1 + I Step -1 'abwärts
If Feld(J - 1) > Feld(J) Then
Temp = Feld(J)
Feld(J) = Feld(J - 1)
Feld(J - 1) = Temp
End If
Next J
Next I
End Sub