|
@@ -1,26 +1,24 @@
|
1
|
1
|
|
|
2
|
+def partition(lista, p, r):
|
2
|
3
|
|
3
|
|
-def partition(A, p, r):
|
4
|
|
-
|
5
|
|
- x = A[r]
|
|
4
|
+ x = lista[r]
|
6
|
5
|
i = p - 1
|
7
|
6
|
|
8
|
7
|
for j in range (p, r):
|
9
|
8
|
|
10
|
|
- if A[j] <= x:
|
|
9
|
+ if lista[j] <= x:
|
11
|
10
|
i += 1
|
12
|
|
- A[j], A[i] = A[i], A[j]
|
|
11
|
+ lista[j], lista[i] = lista[i], lista[j]
|
13
|
12
|
|
14
|
|
- A[i+1], A[r] = A[r], A[i+1]
|
|
13
|
+ lista[i+1], lista[r] = lista[r], lista[i+1]
|
15
|
14
|
|
16
|
15
|
return i + 1
|
17
|
16
|
|
18
|
17
|
|
19
|
|
-
|
20
|
|
-def qSort(A, p, r):
|
|
18
|
+def qSort(lista, p, r):
|
21
|
19
|
|
22
|
20
|
if p < r:
|
23
|
|
- q = partition(A, p, r)
|
24
|
|
- qSort(A, p, q - 1)
|
25
|
|
- qSort(A, q + 1, r)
|
|
21
|
+ q = partition(lista, p, r)
|
|
22
|
+ qSort(lista, p, q - 1)
|
|
23
|
+ qSort(lista, q + 1, r)
|
26
|
24
|
|