A merge sort works as follows:
- Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted).
- Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.
An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged. (Via Wikipedia)
static protected int a;
public static void main(String args)throws IOException
BufferedReader obj= new BufferedReader (new InputStreamReader (System.in));
System.out.println(“Enter number of elements:”);
for (int i=0;i