Finds the median of the elements between the specified range. @param arr the input array @param begin the starting index @param end the ending index @return the median of the specified range
(int[] arr, int begin, int end)
| 135 | * @return the median of the specified range |
| 136 | */ |
| 137 | public static int getMedian(int[] arr, int begin, int end) { |
| 138 | insertionSort(arr, begin, end); |
| 139 | int sum = begin + end; |
| 140 | int mid = sum / 2 + (sum % 2); |
| 141 | return arr[mid]; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Sorts a portion of the array using insertion sort. |