-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquicksort.py
More file actions
33 lines (25 loc) · 804 Bytes
/
quicksort.py
File metadata and controls
33 lines (25 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def pivot(array, start, end):
#initialize
pivot = array[start]
low = start + 1
high = end
while True:
while low <= high and array[high] >= pivot:
high = high -1
while low <= high and array[low] <= pivot:
low = low + 1
if low <= high:
array[low], array[high] = array[high], array[low]
else:
break
array[start], array[high] = array[high], array[start]
return high
def quicksort (array, start, end):
if start >= end:
return
p = pivot(array, start, end)
quicksort(array,start,p-1)
quicksort(array,p+1, end)
array = [6,3,3,2,9,2]
quicksort(array, 0, len(array)-1)
print(array)