MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / partition

Function partition

QuickSort.py:13–31  ·  view source on GitHub ↗
(alist, first, last)

Source from the content-addressed store, hash-verified

11 quickSortHelper(alist, splitPoint+1, last)
12
13def partition(alist, first, last):
14 pivotvlue = alist[first]
15
16 leftmark = first+1
17 rightmark = last
18 done = False
19
20 while not done:
21 while leftmark <= rightmark and alist[leftmark] <= pivotvlue: # bugfix: 先比较index, 不然数组会越界
22 leftmark += 1
23 while rightmark >= leftmark and alist[rightmark] >= pivotvlue:
24 rightmark -= 1
25
26 if leftmark > rightmark:
27 done = True
28 else:
29 alist[leftmark], alist[rightmark] = alist[rightmark], alist[leftmark]
30 alist[rightmark], alist[first] = alist[first], alist[rightmark]
31 return rightmark
32
33alist = [54,26,93,17,77,31,44,55,20]
34alist2 = [1]

Callers 1

quickSortHelperFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected