Mergesort 1
Mergesort 1
Assignment no. 00: Assume we have two input and two output tapes to
perform the sorting. The internal memory can hold and sort m records at a
time. Write a program in Java for external sorting. Find out time
complexity. */
import java.util.Scanner;
class MergeSort
{
// Divide the array into two subarrays, sort them and merge them
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of elements you want to store:
");
//reading the number of elements from the that we want to enter
n=sc.nextInt();
System.out.println("Sorted array:");
printArray(arr);
}
}
/*
Output:
Enter the number of elements you want to store: 6
Enter the elements of the array:
45 12 78 34 23 10
Enter Array before sorting
Array before sorting
45 12 78 34 23 10
Sorted array:
10 12 23 34 45 78
*/