Wednesday, March 2, 2011

2.3:
take your priority queue, instead of ints, it should take Comparable objects. alternatively, you can make the constructor take a Comparator object of your own creation.
do both
*eventually*, it should implement Queue interface.

http://onjava.com/pub/a/onjava/2003/03/12/java_comp.html

if (a.compareTo(b) == 0)
// equivalent to: if (a == b)

if (a.compareTo(b) < 0)
// equivalent to: if (a < b)

if (a.compareTo(b) > 0)
// equivalent to: if (a > b)

Comparator
http://www.javadeveloper.co.in/java-example/java-comparator-example.html

No comments:

Post a Comment