MCPcopy Index your code
hub / github.com/careercup/ctci / partition

Method partition

java/Chapter 18/Question18_6/QuestionC.java:81–96  ·  view source on GitHub ↗
(int[] array, int left, int right, int pivot)

Source from the content-addressed store, hash-verified

79 }
80
81 public static int partition(int[] array, int left, int right, int pivot) {
82 while (true) {
83 while (left <= right && array[left] <= pivot) {
84 left++;
85 }
86
87 while (left <= right && array[right] > pivot) {
88 right--;
89 }
90
91 if (left > right) {
92 return left - 1;
93 }
94 swap(array, left, right);
95 }
96 }
97
98 public static int rank(int[] array, int left, int right, int rank) {
99 int pivot = array[randomIntInRange(left, right)];

Callers 2

validateFullMethod · 0.95
rankMethod · 0.95

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected