Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs
- ;Output:
- Array in: 4, 3, 2, 1
- Quicksort: 0, 3
- Partition: 0, 3
- 4 ,3 ,2 ,1
- i|pj | | |r
- 4 ,3 ,2 ,1
- i|p |j | |r
- 4 ,3 ,2 ,1
- i|p | |j |r
- 1 ,3 ,2 ,4
- i|p | | |rj
- Quicksort: 0, -1
- Quicksort: 1, 3
- Partition: 1, 3
- 1 ,3 ,2 ,4
- |i |pj | |r
- 1 ,3 ,2 ,4
- | |pi |j |r
- 1 ,3 ,2 ,4
- | |p |i |rj
- Quicksort: 1, 2
- Partition: 1, 2
- 1 ,3 ,2 ,4
- |i |pj |r |
- 1 ,2 ,3 ,4
- |i |p |rj |
- Quicksort: 1, 0
- Quicksort: 2, 2
- Quicksort: 4, 3
- Array out: 1, 2, 3, 4
- Array in: 6, 7, 3, 1, 4, 9, 5, 6, 7
- Quicksort: 0, 8
- Partition: 0, 8
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- i|pj | | | | | | | |r
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- |pi |j | | | | | | |r
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- |p |i |j | | | | | |r
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- |p | |i |j | | | | |r
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- |p | | |i |j | | | |r
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- |p | | | |i |j | | |r
- 6 ,7 ,3 ,1 ,4 ,9 ,5 ,6 ,7
- |p | | | |i | |j | |r
- 6 ,7 ,3 ,1 ,4 ,5 ,9 ,6 ,7
- |p | | | | |i | |j |r
- 6 ,7 ,3 ,1 ,4 ,5 ,6 ,7 ,9
- |p | | | | | |i | |rj
- Quicksort: 0, 6
- Partition: 0, 6
- 6 ,7 ,3 ,1 ,4 ,5 ,6 ,7 ,9
- i|pj | | | | | |r | |
- 6 ,7 ,3 ,1 ,4 ,5 ,6 ,7 ,9
- |pi |j | | | | |r | |
- 6 ,7 ,3 ,1 ,4 ,5 ,6 ,7 ,9
- |pi | |j | | | |r | |
- 6 ,3 ,7 ,1 ,4 ,5 ,6 ,7 ,9
- |p |i | |j | | |r | |
- 6 ,3 ,1 ,7 ,4 ,5 ,6 ,7 ,9
- |p | |i | |j | |r | |
- 6 ,3 ,1 ,4 ,7 ,5 ,6 ,7 ,9
- |p | | |i | |j |r | |
- 6 ,3 ,1 ,4 ,5 ,6 ,7 ,7 ,9
- |p | | | |i | |rj | |
- Quicksort: 0, 4
- Partition: 0, 4
- 6 ,3 ,1 ,4 ,5 ,6 ,7 ,7 ,9
- i|pj | | | |r | | | |
- 6 ,3 ,1 ,4 ,5 ,6 ,7 ,7 ,9
- i|p |j | | |r | | | |
- 3 ,6 ,1 ,4 ,5 ,6 ,7 ,7 ,9
- |pi | |j | |r | | | |
- 3 ,1 ,6 ,4 ,5 ,6 ,7 ,7 ,9
- |p |i | |j |r | | | |
- 3 ,1 ,4 ,5 ,6 ,6 ,7 ,7 ,9
- |p | |i | |rj | | | |
- Quicksort: 0, 2
- Partition: 0, 2
- 3 ,1 ,4 ,5 ,6 ,6 ,7 ,7 ,9
- i|pj | |r | | | | | |
- 3 ,1 ,4 ,5 ,6 ,6 ,7 ,7 ,9
- |pi |j |r | | | | | |
- 3 ,1 ,4 ,5 ,6 ,6 ,7 ,7 ,9
- |p |i |rj | | | | | |
- Quicksort: 0, 1
- Partition: 0, 1
- 3 ,1 ,4 ,5 ,6 ,6 ,7 ,7 ,9
- i|pj |r | | | | | | |
- 1 ,3 ,4 ,5 ,6 ,6 ,7 ,7 ,9
- i|p |rj | | | | | | |
- Quicksort: 0, -1
- Quicksort: 1, 1
- Quicksort: 3, 2
- Quicksort: 4, 4
- Quicksort: 6, 6
- Quicksort: 8, 8
- Array out: 1, 3, 4, 5, 6, 6, 7, 7, 9
- #ce
- ;Programm:
- #include <String.au3>
- #include <Array.au3>
- Dim $Array1[4] = [4, 3, 2, 1]
- Dim $Array2[9] = [6, 7, 3, 1, 4, 9, 5, 6, 7]
- Test($Array1)
- Test($Array2)
- Func Test($Array)
- ConsoleWrite("Array in: ")
- ArrayPrint($Array)
- Quicksort($Array, 0, UBound($Array) - 1)
- ConsoleWrite("Array out: ")
- ArrayPrint($Array)
- EndFunc
- Func Quicksort(ByRef $A, $p, $r)
- ConsoleWrite("Quicksort: " & $p & ", " & $r & @CR)
- If $p < $r Then
- Local $q = Partition($A, $p, $r)
- Quicksort($A, $p, $q - 1)
- Quicksort($A, $q + 1, $r)
- EndIf
- EndFunc
- Func Partition(ByRef $A, $p, $r)
- ConsoleWrite("Partition: " & $p & ", " & $r & @CR)
- Local $x = $A[$r]
- Local $i = $p - 1
- For $j = $p To $r - 1
- PrintStuff($A, $p, $r, $j, $i)
- If $A[$j] <= $x Then
- $i = $i + 1
- Vertausche($A, $i, $j)
- EndIf
- Next
- Vertausche($A, $i + 1, $r)
- PrintStuff($A, $p, $r, $j, $i)
- Return $i + 1
- EndFunc
- Func Vertausche(ByRef $A, $i, $j)
- Local $x = $A[$i]
- $A[$i] = $A[$j]
- $A[$j] = $x
- EndFunc
- Func PrintStuff($A, $p, $r, $j, $i)
- Local $x = " "
- Local $y = " |"
- If $i = -1 Then $y = "i|"
- For $n = 0 To UBound($A) - 1
- Local $t = ""
- Local $t2 = ""
- $x &= $A[$n] & " ,"
- If $p = $n Then
- $t2 &= "p"
- Else
- $t &= " "
- EndIf
- If $r = $n Then
- $t2 &= "r"
- Else
- $t &= " "
- EndIf
- If $j = $n Then
- $t2 &= "j"
- Else
- $t &= " "
- EndIf
- If $i = $n Then
- $t2 &= "i"
- Else
- $t &= " "
- EndIf
- $y &= StringLeft($t2 & $t, 3) & "|"
- Next
- ConsoleWrite(StringLeft($x, StringLen($x) - 1) & @CR)
- ConsoleWrite(StringLeft($y, StringLen($x) - 1) & @CR)
- EndFunc
- Func ArrayPrint($A)
- Local $x = ""
- For $n = 0 To UBound($A) - 1
- $x &= $A[$n] & ", "
- Next
- ConsoleWrite(StringLeft($x, StringLen($x) - 2) & @CR)
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement