0

So I am reading in a txt file with a list of unsorted numbers...

14 36 9 87 2 5

My recursive method for the binary search is...

public static int bSearch(int[] a, int lo, int hi, int key)
 {
    int mid = lo+(lo + hi)/2;

    if (lo <= hi) 
        return -(lo+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);
}

I want to sort the values by implementing the recursive binary search. Can someone point me in the direction on how I would go about doing this.

1
  • 2
    Searching and Sorting are two different things, using one to do the the other would be tricky. You could look at quicksort which is a binary division sorting method. Commented Feb 25, 2014 at 3:57

3 Answers 3

1

Why use binary search for sorting? If you are really looking for divide and conquer strategy, please have a look at merge sort.

Sign up to request clarification or add additional context in comments.

Comments

0

It is possiable to sort using binary search. Take a look: Binary Searching and Sorting

Comments

0

Binary search algorithm uses for searching.I guess you mixed up binary search with quicksort algorithm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.