MCPcopy Create free account
hub / github.com/AdarshAddee/Hacktoberfest2022_for_Beginers / partition

Method partition

Java/QuickSort.java:8–27  ·  view source on GitHub ↗
(int[] arr, int si, int ei)

Source from the content-addressed store, hash-verified

6public class QuickSort {
7
8 public static int partition(int[] arr, int si, int ei) {
9 int pid, piv = arr[si], count = 0, i = si;
10 for (i = si + 1; i <= ei; i++) {
11 if (arr[i] <= piv) {
12 count++;
13 }
14 }
15 pid = count + si;
16 arr[si] = (arr[pid] + arr[si]) - (arr[pid] = arr[si]);
17 while (si < pid && ei > pid) {
18 if (arr[si] < piv) {
19 si++;
20 } else if (arr[ei] > piv) {
21 ei--;
22 } else {
23 arr[si] = (arr[ei] + arr[si]) - (arr[ei--] = arr[si++]);
24 }
25 }
26 return pid;
27 }
28
29 public static void quickSort(int[] arr, int si, int ei) {
30 if (si < ei) {

Callers 1

quickSortMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected