Can anyone help with me this? Thanks.. i have no idea what to putin the main how
ID: 3618610 • Letter: C
Question
Can anyone help with me this? Thanks.. i have no idea what to putin the main how it works.using jgrasp program (java) thanks.
// Merge Sort
public class MergeSort
{
public static void main(String [] args)
{
// What should I put in the main? no idea
}
public static void mergeSort(int list[], int first, int last)
{
if(first < last)
{
int mid = (first + last)/2;
mergeSort(list, first, mid);// sort left half
mergeSort(list, mid+1, last);// sort right half
Merge(list,first, mid,last);
}
}
public static void Merge(int list[], int first, int mid, intlast)
{
int first1= first, last1= mid;
int first2 = mid+1, last2 = last;
int temp [] = new int [list.length];
int index = first1;
while(first1 <= last1 && first2 <=last2)
{
if(list[first1] <list[first2])
temp[index] = list[first1++];
else
temp[index] = list[first2++];
index++;
}
while(first1 <= last1)
temp[index++] =list[first1++];
while(first2 <= last2)
temp[index++] =list[first2++];
for(index = first; index<= last; index++)
list[index] = temp[index];
}
}
Test the mergeSort() method for n= 8 random integers and record thenumber of comparisons. Repeat the test for n = 16, n = 32, n= 64, n = 128, n= 256, n = 512, and n=1024.
Explanation / Answer
Dear... Here is the code for main method with date in arrayinitialized. public static void main(String[] args){
int List[] ={1,4,7,12,8,5,14,6,9,13,10,2};
System.out.println("Before sorting:");
for(int i=0;i<11;i++)
System.out.print(List[i]+" ");
mergeSort(List,0,11);
System.out.println("After sorting:");
for(int i=0;i<11;i++)
System.out.print(List[i]+" ");
System.exit(0);
} Hope this will help you... Hope this will help you...
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.