binary sort in java

Post about everything you want - even if it is not related to programming or this site.

Moderator: Board moderators

Post Reply
ushujerra
New poster
Posts: 1
Joined: Thu Mar 07, 2013 9:17 pm

binary sort in java

Post by ushujerra » Mon Mar 18, 2013 5:58 am

How do I write this binary sort in java using array?
You have write a method that will use binary search to see if a given element is in the array. Assume that the array is already sorted in ascending order. I don't understand binary searches, but if someone shows me through this method what a binary search does, I would be grateful. Thank you.
public boolean findNum(int[] nums, int theNum)
{
}
Last edited by ushujerra on Wed Mar 20, 2013 1:44 am, edited 1 time in total.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Re: binary sort in java

Post by Darko » Tue Mar 19, 2013 1:17 am

Code: Select all

public boolean findNum(int[] nums, int theNum)
{
  return Arrays.binarySearch(nums, theNum) >= 0;
}

Post Reply

Return to “Off topic (General chit-chat)”