• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Search for String  RSS feed

 
asa aza
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello.. i really need help here, im weak in java.. im doing dictionary application for android.. i have problem in searching for the words from my text file.. im using binary search technique

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binary search is used on sorted input. The line you are reading from the file may not be sorted. So you need to sort it before you can use it.

Secondly, you are reading single line only. you should read it in loop for reading file completely.
 
asa aza
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wat about i put it this way.. i dont want to use the binary search technique

do searchQuery (searchQuery)
for (int i=0; i<myLine.length(); i++) {
System.out.println("Maksud/meaning : " + i + 1); 
System.out.println("Contoh ayat : " + i + 2);
break; } 
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest to you stop coding right now. Switch off your monitor. Take a pen and paper, put up your thoughts into the paper. Once you write it
down then convert your idea into the code. Otherwise you are going into wrong direction.

By the way for your case you are printing the indices.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have got some good advice there, and you would do well to follow it.

I have added code tags to your post (always use them) and removed some unnecessary blank lines. Doesn't it look better now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!