-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick_sort.py
48 lines (39 loc) · 1.04 KB
/
quick_sort.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
43
44
45
46
47
48
# quick sort
list1 = [12,18,15,21,19,30,4,17, 30,17]
N = 0
def sort(listN,startP,endP,N):
print()
print("listN", listN)
# print("startP", startP)
# print("endP", endP)
print("sorting")
privote = listN[endP]
print("privote:", privote)
smallL = []
bigL = []
for item in listN[startP:endP]:
if item <= privote:
smallL.append(item)
if item > privote:
bigL.append(item)
partList = smallL
partList.append(privote)
# partList = partList + bigL
partList.extend(bigL)
print("partList", partList)
endList = listN
endList[startP:endP+1] = partList
print("end list", endList)
if len(smallL) > 1:
N+=1
print("smallL",smallL)
print("N",N)
sort(endList,startP,startP + len(smallL) - 2,N)
if len(bigL) > 1:
N+=1
print("bigL",bigL)
print("N",N)
sort(endList,endP - len(bigL),endP,N)
return endList
ans = sort(list1,0,len(list1)-1,0)
print("=============", ans, "=============")