• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Search of Collection is not Finding Matches  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the array I know elements exists that the following code is not finding:

My array code:



My search code:

 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, what does your data look like?

As far as I can tell you
- run a query on a database and return a list of results
- do a binary search on the list of results.

Can you provide an example of what the data looks like coming back from your mfgDates.getDateNumberArrayList() method?
What are the assumptions that a binary search makes about the input list?
Are those assumptions being met?

 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I discovered I have to do a sort on the collection before the search. It works great after that. Sorry for the bother.
 
Carey Brown
Saloon Keeper
Posts: 3312
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binary search only works on sorted data. You may want to add this to your SQL: ORDER BY caldt.

Edit: dang, you beat me
 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Binary search only works on sorted data. You may want to add this to your SQL: ORDER BY caldt.

Edit: dang, you beat me


Thanks.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!