Results 1 to 2 of 2
Thread: Problem with binary search
- 03-05-2011, 09:20 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Problem with binary search
Hi everyone.
Can anyone tell me how to create an array of Comparable objects to test my binary search? I need to create a driver
Java Code:public class Searching public static Comparable binarySearch (Comparable[] data, Comparable target) { Comparable result = null; int first = 0, last = data.length-1, mid; while (result == null && first <= last) { mid = (first + last) / 2; // determine midpoint if (data[mid].compareTo(target) == 0) result = data[mid]; else if (data[mid].compareTo(target) > 0) last = mid - 1; else first = mid + 1; } return result; } }Last edited by Chi; 03-07-2011 at 09:06 PM.
- 03-07-2011, 03:23 AM #2
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Binary search problem
By billy in forum New To JavaReplies: 3Last Post: 10-08-2010, 08:43 PM -
Custom binary search problem
By PtblDuffy in forum New To JavaReplies: 2Last Post: 09-16-2010, 08:53 PM -
Binary Search Problem
By sharpnova in forum New To JavaReplies: 2Last Post: 02-19-2009, 10:22 AM -
Help. Binary Search Problem
By Krooger in forum Advanced JavaReplies: 1Last Post: 11-03-2008, 06:19 AM -
problem with recursive binary search program
By imran_khan in forum New To JavaReplies: 3Last Post: 08-02-2007, 03:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks