MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / partition

Method partition

Lecture 42 Quick Sort/src/Main.java:12–31  ·  view source on GitHub ↗
(int[] arr, int st, int end)

Source from the content-addressed store, hash-verified

10 arr[y] = temp;
11 }
12 static int partition(int[] arr, int st, int end){
13 int pivot = arr[st];
14 int cnt = 0;
15 for(int i = st+1; i <= end; i++){
16 if(arr[i] <= pivot) cnt++;
17 }
18 int pivotIdx = st + cnt;
19 swap(arr, st, pivotIdx);
20 int i = st, j = end;
21 while(i < pivotIdx && j > pivotIdx){
22 while (arr[i] <= pivot) i++;
23 while (arr[j] > pivot) j--;
24 if(i < pivotIdx && j > pivotIdx){
25 swap(arr, i, j);
26 i++;
27 j--;
28 }
29 }
30 return pivotIdx;
31 }
32 static void quickSort(int[] arr, int st, int end){
33 if(st >= end) return;
34 int pi = partition(arr, st, end);

Callers 1

quickSortMethod · 0.95

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected