(int start, int mid, int end)
| 35 | } |
| 36 | |
| 37 | private static void merge(int start, int mid, int end) { |
| 38 | int[] tempArray=new int[arr.length]; |
| 39 | int tempArrayIndex=start; |
| 40 | |
| 41 | System.out.print("Before Merging: "); |
| 42 | printArray(arr,start,end); |
| 43 | |
| 44 | int startIndex=start; |
| 45 | int midIndex=mid+1; |
| 46 | |
| 47 | while(startIndex<=mid && midIndex<=end) |
| 48 | { |
| 49 | if(arr[startIndex]< arr[midIndex]) |
| 50 | { |
| 51 | tempArray[tempArrayIndex++]=arr[startIndex++]; |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | tempArray[tempArrayIndex++]=arr[midIndex++]; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | while(startIndex<=mid) |
| 60 | { |
| 61 | tempArray[tempArrayIndex++]=arr[startIndex++]; |
| 62 | } |
| 63 | while(midIndex<=end) |
| 64 | { |
| 65 | tempArray[tempArrayIndex++]=arr[midIndex++]; |
| 66 | } |
| 67 | |
| 68 | for (int i = start; i <=end; i++) { |
| 69 | arr[i]=tempArray[i]; |
| 70 | } |
| 71 | |
| 72 | System.out.print("After merging: "); |
| 73 | printArray(tempArray,start,end); |
| 74 | System.out.println(); |
| 75 | } |
| 76 | |
| 77 | public static void printArray(int arr[],int start,int end) |
| 78 | { |
no test coverage detected