23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Code Fragment 8.3: Class represent<strong>in</strong>g po<strong>in</strong>ts <strong>in</strong><br />

the plane with <strong>in</strong>teger coord<strong>in</strong>ates.<br />

8.1.3 The Priority Queue ADT<br />

Hav<strong>in</strong>g described the composition <strong>and</strong> comparator patterns, let us now def<strong>in</strong>e the<br />

priority queue ADT, to support the follow<strong>in</strong>g method for a priority queue P:<br />

size():<br />

Return the number of entries <strong>in</strong> P.<br />

isEmpty():<br />

Test whether P is empty.<br />

m<strong>in</strong>():<br />

Return (but do not remove) an entry of P with smallest key; an error<br />

condition occurs if P is empty.<br />

<strong>in</strong>sert(k,x):<br />

Insert <strong>in</strong>to P key k with value x <strong>and</strong> return the entry stor<strong>in</strong>g them; an error<br />

condition occurs if k is <strong>in</strong>valid (that is, k cannot be compared with other<br />

keys.<br />

removeM<strong>in</strong>():<br />

Remove from P <strong>and</strong> return an entry with smallest key; an error condition<br />

occurs if P is empty.<br />

455

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!