Sorting arrays using a recursive binary search

How would I use a recursive binary search to sort a list of unsorted numbers e.g.

My code for the recursive binary search is....

Code :

public static int bSearch(int[] a, int lo, int hi, int key)
{
int mid = (lo+hi)/2;
if(lo>hi)
return -1;
else if (a[mid]==key)
return mid;
else if (a[mid]<key)
return bSearch(a, mid+1, hi, key);
else
return bSearch(a, lo, mid-1, key);
}

My insert in order method would be....

Code :

static void insertInOrder( int[] arr, int cnt, int newVal )
{
int index = -( bSearch( arr, 0, arr.length-1, newVal)) - 1;
//Stuck here ********************
}

Re: Sorting arrays using a recursive binary search

Welcome to the forum! Thanks for taking the time to learn how to post code correctly.

Re: Sorting arrays using a recursive binary search

Quote:

recursive binary search

does it mean that you are not allowed to use a loop? maybe it is an assignment, i guess.

Quote:

My insert in order method would be....

do you really need another method for interchanging the values?

do you know how to sort an array using loop with nested loop?

i think it is called a bubble sort.

I think it would be easier to explain how to do that if you at least understand how to create a bubble sort program.