-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick.py
42 lines (30 loc) · 802 Bytes
/
quick.py
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
34
35
36
37
38
39
40
41
42
def quick(lst):
quickSort(lst,0,len(lst)-1)
def quickSort(lst,start,end):
if start<end:
pivot = partition(lst,start,end)
quickSort(lst,start,pivot-1)
quickSort(lst,pivot+1,end)
def partition(lst,start,end):
pivotvalue = lst[start]
left = start+1
right = end
done = False
while not done:
while left <= right and lst[left] <= pivotvalue:
left = left + 1
while lst[right] >= pivotvalue and right >= left:
right = right -1
if right < left:
done = True
else:
temp = lst[left]
lst[left] = lst[right]
lst[right] = temp
temp = lst[start]
lst[start] = lst[right]
lst[right] = temp
return right
lst = [54,26,93,17,77,31,44,55,20]
quick(lst)
print(lst)