Results 1 to 1 of 1
- 08-23-2009, 09:20 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 11
- Rep Power
- 0
Divide and Conquer@Array...im becoming crazy!
Hello Guys, i have a little logic problem in my program. The program is easy, has no real use and is for my learning only.
I try to implement a divideandconquer searchalgorithm inside an array.
For this purpose i am using a method who uses two parameters, a stringarray and the searchedname.
The problem:
If the searchedString is not the median ( array.length/2), it should look above or under the name in the array. I dont know how to implement this. The check if the value is more or less than the medianvalue works...but how do i implement that the method is using a "shorter part" of the array e.g. median+1 -> array.length for values greater than median or array[0]->median -1.
Here the method...i know the problem is very simple but it makes me mad that i am too stupid to udnerstand how it works.
Help me!!!Java Code:public static int searchNameDivideConquer(String[] names,String searchedName){ int median = names.length/2; int counter = 0; if (names[median].equals(searchedName)){ counter++; System.out.println("Name " + searchedName + " found!"); return counter; }else { if (searchedName.compareTo(names[median]) >1){ [COLOR="Red"]???[/COLOR] counter ++; System.out.println("Name " + searchedName + " found!"); } if (searchedName.compareTo(names[median])<1){ [COLOR="Red"] ???[/COLOR] counter ++; System.out.println("Name " + searchedName + " found!"); } } return counter; }
Similar Threads
-
crash on freebsd eclipse 3.4.2 caused by evaluating divide-by-zero
By jmak in forum EclipseReplies: 2Last Post: 08-04-2009, 12:35 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM -
How to divide code in classes?
By hendrix79 in forum New To JavaReplies: 2Last Post: 12-10-2008, 05:36 PM -
Please tell me I am not crazy... Time Complexity (Big-O) Question
By Jordan in forum New To JavaReplies: 2Last Post: 11-04-2008, 02:48 AM -
Errors driving me crazy! although compiles fine
By irishsea2828 in forum New To JavaReplies: 1Last Post: 04-08-2008, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks