Priority Queues and Heaps_Part_2

Priority Queues and Heaps_Part_2 - Entry ADT An entry in a...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Last Updated: 06/02/12 8:32 PM CSE 2011 Prof. J. Elder - 6 - Entry ADT An entry in a priority queue is simply a key- value pair Methods: key (): returns the key for this entry value (): returns the value for this entry As a Java interface: /** * Interface for a key-value * pair entry **/ public interface Entry { public Object key(); public Object value(); }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Last Updated: 06/02/12 8:32 PM CSE 2011 Prof. J. Elder - 7 - 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.
Background image of page 2
Last Updated: 06/02/12 8:32 PM CSE 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Priority Queues and Heaps_Part_2 - Entry ADT An entry in a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online