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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Thus, a doubly l<strong>in</strong>ked list can be used to implement each method of the deque ADT<br />

<strong>in</strong> constant time. We leave the details of implement<strong>in</strong>g the deque ADT efficiently <strong>in</strong><br />

<strong>Java</strong> as an exercise (P-5.7).<br />

Incidentally, all of the methods of the deque ADT, as described above, are <strong>in</strong>cluded<br />

<strong>in</strong> the java.util.L<strong>in</strong>kedList class. So, if we need to use a deque <strong>and</strong><br />

would rather not implement one from scratch, we can simply use the built-<strong>in</strong><br />

java.util.L<strong>in</strong>kedList class.<br />

In any case, we show a Deque <strong>in</strong>terface <strong>in</strong> Code Fragment 5.17 <strong>and</strong> an<br />

implementation of this <strong>in</strong>terface <strong>in</strong> Code Fragment 5.18.<br />

Code Fragment 5.17: Interface Deque documented<br />

with comments <strong>in</strong> <strong>Java</strong>doc style (Section 1.9.3). Note<br />

also the use of the generic parameterized type, E, which<br />

implies that a deque can conta<strong>in</strong> elements of any<br />

specified class.<br />

301

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

Saved successfully!

Ooh no, something went wrong!