• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Search  RSS feed

 
tom washington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to implement a binary search. I have a array list and a linked list but the array list is what I am focused on. I already sorted it but the binary search will not work, I keep getting the error: no suitable method found for binary search(). Any help/advice on what I am doing wrong would be very helpful, thank you.



 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Collections.binarySearch has to compare your collection to a key of the same type.

 
tom washington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey, I am still getting the exact same error. Is it possible there is something wrong in the rest of my code? I am just confused because it runs fine until I try to use binarySearch.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using some old Java stuff here.
Stack has been replaced by Deque
This is from the 'Stack' documentation:

A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example:

Deque<Integer> stack = new ArrayDeque<Integer>();
 
tom washington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a project that I am working on that requires me to use these operations.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deque still supports push() and pop() operations.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashTable...
As of the Java 2 platform v1.2, this class was retrofitted to implement the Map interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Hashtable is synchronized. If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable. If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of Hashtable
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can post the code for Contributor, that would be helpful. And if you want us to run your code, make sure you PostRealCode (← that's a link).

Other comments not directly related to the error: you have four public static fields. This is usually a mistake. First, make them private and if they need to be accessed outside the class, create setters and getters. Second, they're static. I would think you need instance fields (nonstatic). Do you really only want one copy of contributorStack, etc.? Which leads into...

Too much code is in main. main should start the program running. That's it. See MainIsAPain.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!