Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub sortieren()
- Dim a(1 To 5, 1 To 2) As Integer
- Dim i As Integer, j As Integer
- 'Einlesen
- For i = 1 To 5
- For j = 1 To 2
- a(i, j) = Cells(i, j)
- Next j
- Next i
- 'Aufruf quicksort
- Call quicksort(1, 5, a(), 1)
- 'ausgabe
- For i = 1 To 5
- For j = 1 To 2
- Cells(i, j + 3) = a(i, j)
- Next j
- Next i
- End Sub
- Sub quicksort(ByVal u As Integer, ByVal o As Integer, ByRef a() As Integer, spalte As Integer)
- 'u=listenanfang, o=listenende
- If u < o Then
- Dim i As Integer, j As Integer
- i = u
- j = o - 1
- While i < j
- While a(i, spalte) <= a(o, spalte) And i < o
- i = i + 1
- Wend
- While a(j, spalte) >= a(o, spalte) And j > u
- j = j - 1
- Wend
- If i < j Then
- Call tausche2(a(), i, j)
- End If
- Wend
- If a(i, spalte) > a(o, spalte) Then
- Call tausche2(a(), i, o)
- End If
- Call quicksort(u, i - 1, a, spalte)
- Call quicksort(i + 1, o, a, spalte)
- End If
- End Sub
- Sub tausche2(ByRef a() As Integer, ByVal zeile1 As Integer, ByVal zeile2 As Integer)
- Dim h As Integer, i As Integer
- For i = 1 To 2
- h = a(zeile1, i)
- a(zeile1, i) = a(zeile2, i)
- a(zeile2, i) = h
- Next i
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement