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.

A Queue Interface <strong>in</strong> <strong>Java</strong><br />

A <strong>Java</strong> <strong>in</strong>terface for the queue ADT is given <strong>in</strong> Code Fragment 5.13. This generic<br />

<strong>in</strong>terface specifies that objects of arbitrary object types can be <strong>in</strong>serted <strong>in</strong>to the<br />

queue. Thus, we don't have to use explicit cast<strong>in</strong>g when remov<strong>in</strong>g elements.<br />

Note that the size <strong>and</strong> isEmpty methods have the same mean<strong>in</strong>g as their<br />

counterparts <strong>in</strong> the Stack ADT. These two methods, as well as the front method,<br />

are known as accessor methods, for they return a value <strong>and</strong> do not change the<br />

contents of the data structure.<br />

Code Fragment 5.13: Interface Queue documented<br />

with comments <strong>in</strong> <strong>Java</strong>doc style.<br />

288

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

Saved successfully!

Ooh no, something went wrong!