Embed presentation
Download to read offline
![Java - a mergeSort algorithm using arraylists or arrays
Solution
/* Java implementation of for Merge Sort using arrays */
class MergeSort
{
// merging the two subarrays
void merge(int intArray[], int left, int middle, int right)
{
int length1 = middle - left + 1;
int length2 = right - middle;
// First subarray is arr[left..middle]
int Larray[] = new int [length1];
// Second subarray is arr[middle+1..right]
int Rarray[] = new int [length2];
/*Copy data to arrays*/
for (int i=0; i](https://image.slidesharecdn.com/java-amergesortalgorithmusingarraylistsorarrayssolution-230323121434-b2577efe/75/Java-a-mergeSort-algorithm-using-arraylists-or-arraysSolution-pdf-1-2048.jpg)
The document provides a Java implementation of the mergesort algorithm using either ArrayLists or arrays. It focuses on the merging of two subarrays, defining the necessary components and loops for copying data into the subarrays. The code facilitates sorting an array efficiently by dividing it into smaller subarrays.
![Java - a mergeSort algorithm using arraylists or arrays
Solution
/* Java implementation of for Merge Sort using arrays */
class MergeSort
{
// merging the two subarrays
void merge(int intArray[], int left, int middle, int right)
{
int length1 = middle - left + 1;
int length2 = right - middle;
// First subarray is arr[left..middle]
int Larray[] = new int [length1];
// Second subarray is arr[middle+1..right]
int Rarray[] = new int [length2];
/*Copy data to arrays*/
for (int i=0; i](https://image.slidesharecdn.com/java-amergesortalgorithmusingarraylistsorarrayssolution-230323121434-b2577efe/75/Java-a-mergeSort-algorithm-using-arraylists-or-arraysSolution-pdf-1-2048.jpg)