forked from Jack-Lee-Hiter/AlgorithmsByPython
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.py
More file actions
Latest commit
34 lines (27 loc) · 952 Bytes
/
Copy pathQuickSort.py
File metadata and controls
34 lines (27 loc) · 952 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
34
defquickSort(alist):
quickSortHelper(alist, 0, len(alist)-1)
defquickSortHelper(alist, first, last):
iffirst<last:
splitPoint=partition(alist, first, last)
quickSortHelper(alist, first, splitPoint-1)
quickSortHelper(alist, splitPoint+1, last)
defpartition(alist, first, last):
pivotvlue=alist[first]
leftmark=first+1
rightmark=last
done=False
whilenotdone:
whilealist[leftmark] <=pivotvlueandleftmark<=rightmark:
leftmark+=1
whilealist[rightmark] >=pivotvlueandrightmark>=leftmark:
rightmark-=1
ifleftmark>rightmark:
done=True
else:
alist[leftmark], alist[rightmark] =alist[rightmark], alist[leftmark]
alist[rightmark], alist[first] =alist[first], alist[rightmark]
returnrightmark
alist= [54,26,93,17,77,31,44,55,20]
alist2= [1]
quickSort(alist2)
print(alist2)