-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathQuickSort.py
More file actions
28 lines (26 loc) · 763 Bytes
/
QuickSort.py
File metadata and controls
28 lines (26 loc) · 763 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
def quickSort(myList, start, end):
if start < end:
pivot = partition(myList, start, end)
quickSort(myList, start, pivot-1)
quickSort(myList, pivot+1, end)
return myList
def partition(myList, start, end):
pivot = myList[start]
left = start+1
right = end
done = False
while not done:
while left <= right and myList[left] <= pivot:
left = left + 1
while myList[right] >= pivot and right >=left:
right = right -1
if right < left:
done= True
else:
temp=myList[left]
myList[left]=myList[right]
myList[right]=temp
temp=myList[start]
myList[start]=myList[right]
myList[right]=temp
return right