Merge Sort Quiz
By Mickey Arnold
starstarstarstarstar
Last updated 10 months ago
4 Questions
public void sort( int[] list, int front, int back)
{
int mid = (front+back)/2;
if( < blank 1 > ) return;
sort(list, front, mid);
sort(list, mid, back);
help(list, front, back);
}
private void help( int[] stuff, int front, int back)
{
int diff = back-front;
int[] temp = new int[ dif ];
int beg = front, mid = (front+back)/2;
int saveMid = mid;
int spot = 0;
while( beg<saveMid && mid<back ) {
if(stuff[ beg ] < stuff[ mid ] )
temp[ spot++ ]= stuff[ beg++ ];
else
temp[ spot++ ]= stuff[ mid++ ];
}
while( beg < saveMid )
temp[ spot++ ]= stuff[ beg++ ];
while( mid < back )
temp[ spot++ ]= stuff[ mid++ ];
for(int i = 0; i < < blank 2 > ; ++i)
stuff[front+i]=temp[i];
}
//code in the main
sort(list, 0, list.length);