MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / partition

Function partition

templates/quicksort.cpp:10–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8}
9
10int partition(int arr[], int low, int high)
11{
12 int anchor = arr[high];
13 int i = low - 1;
14
15 for (int j = low; j <= high - 1; j++) {
16 if (arr[j] <= anchor) {
17 // 永恒经典,一次遍历搞定绕着锚点分大小
18 swap(&arr[++i], &arr[j]);
19 }
20 }
21 // 最后把锚点放到中间来
22 swap(&arr[i + 1], &arr[high]);
23 //返回锚点的位置
24 return i + 1;
25}
26
27void quick_sort(int arr[], int low, int high)
28{

Callers 1

quick_sortFunction · 0.85

Calls 1

swapFunction · 0.85

Tested by

no test coverage detected