import java.time.chrono.JapaneseChronology;
import java.util.Arrays;
public class Main {
public static int binarySort(int[] number, int n) {
int start = 0;
int end = number.length – 1;
while(start <= end){
int middle = (start + end ) / 2;
if(number[middle] == n){
return middle;
}
if(number[middle] > n){
end = middle – 1;
}else{
start = middle + 1;
}
}
return -1;
}
public static void quickSort(int[] number ,int start , int end) {
if(start < end){
int middle = getMiddle(number ,start, end);
quickSort(number, start, middle – 1);
quickSort(number, middle + 1, end);
}
}
private static int getMiddle(int[] number, int start, int end) {
int temp = number[start];
while(start < end){
while(end > start && number[end] > temp){
end –;
}
number[start] = number[end];
while(start < end && number[start] <= temp){
start ++;
}
number[end] = number[start];
}
number[start] = temp;
return start;
}
public static void heapSort(int[] number) {
for(int i = number.length / 2 – 1; i >= 0; i–){
adjustHeap(number, i , number.length – 1);
}
for(int i = number.length – 1; i >= 0; i–){
int temp = number[i];
number[i] = number[0];
number[0] = temp;
adjustHeap(number, 0 , i – 1);
}
}
private static void adjustHeap(int[] number, int i, int end) {
int temp = number[i];
for(int j = 2 * i + 1; j < end; j = 2 * j + 1){
if(j < end && number[j] < number[j + 1] ){
j++;
}
if(temp >= number[j]){
break;
}
number[i] = number[j];
i = j;
}
number[i] = temp;
}
public static void mergeSort(int[] number, int low ,int high ) {
if(low < high){
int middle = (high + low ) / 2;
mergeSort(number, low, middle);
mergeSort(number, middle + 1, high);
merge(number, low , high);
}
}
private static void merge(int[] number, int low, int high) {
int[] temp = new int[high – low + 1];
int middle = (low + high) / 2;
int i = low;
int j = middle + 1;
int k = 0;
while(i <= middle && j <= high){
if(number[i] > number[j]){
temp[k++] = number[j++];
}else{
temp[k++] = number[i++];
}
}
while(i <= middle){
temp[k++] = number[i++];
}
while(j <= high){
temp[k++] = number[j++];
}
k = 0;
for(i = low ; i <= high; i++,k++){
number[i] = temp[k];
}
}
public static void main(String[] args) {
int[] p = {1,2,3,5,9,7,8,9};
mergeSort(p,0 ,p.length – 1);
System.out.println(Arrays.toString(p));
}
}