/end class mergeapp in main(the arrays arrayaarrayband arrayc are createdthen the merge(method is called to merge arraya and arrayb into arraycand the resulting contents of arrayc are displayed here' the output the merge(method has three while loops the first steps along both arraya and arraybcomparing elements and copying the smaller of the two into arrayc the second while loop deals with the situation when all the elements have been transferred out of arraybbut arraya still has remaining elements (this is what happens in the examplewhere and remain in arraya the loop simply copies the remaining elements from arraya into arrayc the third loop handles the similar situation when all the elements have been transferred out of arraya but arrayb still has remaining elementsthey are copied to arrayc sorting by merging the idea in the mergesort is to divide an array in halfsort each halfand then use the merge(method to merge the two halves into single sorted array how do you sort each halfthis is about recursionso you probably already know the answeryou divide the half into two quarterssort each of the quartersand merge them to make sorted half similarlyeach pair of ths is merged to make sorted quartereach pair of ths is merged to make sorted thand so on you divide the array again and again until you reach subarray with only one element this is the base caseit' assumed an array with one element is already sorted we've seen that generally something is reduced in size each time recursive method calls itselfand built back up again each time the method returns in mergesort(the range is divided in half each time this method calls itselfand each time it returns it merges two smaller ranges into larger one as mergesort(returns from finding arrays of element eachit merges them into sorted array of elements each pair of resulting -element arrays is then merged into -element array this process continues with larger and larger arrays until the entire array is sorted this is easiest to see when the original array size is power of as shown in figure