public int[] mergeSort(int[] A, int n) {
return mergeSort(A, firstIndex,lastIndext);
public int[] mergeSort(int[] A, int firstIndex, int lastIndex) {
int mid = firstIndex + (lastIndex - firstIndex)/2;
if(firstIndex < lastIndex){
mergeSort(A, firstIndex,mid);
mergeSort(A, mid+1,lastIndex);
mergeArray(A,firstIndex,mid,lastIndex);
public void mergeArray(int[] A, int firstIndex, int mid, int lastIndex){
int[] temp = new int[lastIndex - firstIndex + 1];
int i = firstIndex, m = mid;
int j = mid + 1, n = lastIndex;
for(int t=0; t<temp.length;){
A[firstIndex++] = temp[t++];