V
vk
short question:
If I have a class with 1 generic type (type T), what is the best way
to compare objects of type T?
bkgd:
We wrote this generic java priority queue which uses a min-heap
(stored in an ArrayList) for class. All of the objects in the min-heap
are of a single (unknown at compile time) type. This unknown type has
to implement java.lang.Comparable so in the priority queue, I can
decide which node to put where. The function to compare objects just
casts them to the Comparable interface and then calls the obj.compareTo
(obj) method.
I'm looking to improve my c++, so I decided to re-write it (in c++).
If there is a Comparable (or similar) interface that works with
primitives and objects, it would be good to know.
If I have a class with 1 generic type (type T), what is the best way
to compare objects of type T?
bkgd:
We wrote this generic java priority queue which uses a min-heap
(stored in an ArrayList) for class. All of the objects in the min-heap
are of a single (unknown at compile time) type. This unknown type has
to implement java.lang.Comparable so in the priority queue, I can
decide which node to put where. The function to compare objects just
casts them to the Comparable interface and then calls the obj.compareTo
(obj) method.
I'm looking to improve my c++, so I decided to re-write it (in c++).
If there is a Comparable (or similar) interface that works with
primitives and objects, it would be good to know.