public class temp {
public static int sorted[] = new int[30];
public static void Msort(int[] arr, int left, int right) {
int center = (left + right) / 2;
Msort(arr, left, center);
Msort(arr, center + 1, right);
Merge(arr, left, center, right);
}
public static void Merge(int[] arr, int lpos, int rpos, int rightend) {
int leftend = rpos - 1;
int sortedindex = lpos;
int start = lpos;
int end = rightend;
while (lpos <= leftend && rpos <= rightend) {
if (arr[lpos] <= arr[rpos]) {
sorted[sortedindex++] = arr[lpos++];
}
else{
sorted[sortedindex++] = arr[rpos++];
}
}
while (lpos <= leftend){
sorted[sortedindex++] = arr[lpos++];
}
while (rpos <= rightend){
sorted[sortedindex++] = arr[rpos++];
}
for (int i = start; i < end; i++){
arr[i] = sorted[i];
}
}
}