-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMergeSortMain.java
37 lines (30 loc) · 1.24 KB
/
MergeSortMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* FILENAME : MergeSortMain.java
* Problem Statement:
* To sort a given set of n integer elements using Merge Sort method.
* ------------------------------------------------------------------------------
* AUTHOR : GANESH PAI, Dept. of CS&E, NMAMIT, Nitte
* YEAR : 2021
* E-mail : ganesh.pai@nitte.edu.in
* ------------------------------------------------------------------------------
*/
import java.util.Arrays;
import java.util.Scanner;
public class MergeSortMain {
public static void main(String[] args) {
Scanner ip = new Scanner(System.in);
//Read input
System.out.print("Enter the number of elements: ");
int noOfElements = ip.nextInt();
System.out.print("Enter " + noOfElements + " integer elements: ");
int data[] = new int[noOfElements];
for(int i=0; i < noOfElements; i++)
data[i] = ip.nextInt();
//Class instance Creation and call for computation
MergeSort ms = new MergeSort(data);
int sorteddata [] = ms.sort();
//Print Results
System.out.println("Unsorted numbers: " + Arrays.toString(data));
System.out.println("Sorted numbers: " + Arrays.toString(sorteddata));
}
}