Last Updated:
1/7/10 10:14 AM
CSE 2011
Prof. J. Elder
- 56 -
Comparator ADT
±
A comparator encapsulates the action of comparing two
objects according to a given total order relation
±
A generic priority queue uses an auxiliary comparator
±
The comparator is external to the keys being compared
±
When the priority queue needs to compare two keys, it
uses its comparator
±
The primary method of the Comparator ADT:
²
compare
(a, b):
³
Returns an integer
i
such that
´
i <
0 if
a < b
´
i
= 0 if
a
=
b
´
i >
0 if
a > b
´
an error occurs if
a
and
b
cannot be compared.

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*