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.

In conclusion, us<strong>in</strong>g a doubly l<strong>in</strong>ked list, we can perform all the methods of the list<br />

ADT <strong>in</strong> O(1) time. Thus, a doubly l<strong>in</strong>ked list is an efficient implementation of the<br />

list ADT.<br />

A Node List Implementation <strong>in</strong> <strong>Java</strong><br />

Portions of the <strong>Java</strong> class NodePositionList, which implements the node list<br />

ADT us<strong>in</strong>g a doubly l<strong>in</strong>ked list, are shown <strong>in</strong> Code Fragments 6.9–6.11. Code<br />

Fragment 6.9 shows NodePosition List's <strong>in</strong>stance variables, its<br />

constructor, <strong>and</strong> a method, checkPosition, which performs safety checks <strong>and</strong><br />

"unwraps" a position, cast<strong>in</strong>g it back to a DNode. Code Fragment 6.10 shows<br />

additional accessor <strong>and</strong> update methods. Code Fragment 6.11 shows additional<br />

update methods.<br />

Code Fragment 6.9: Portions of the<br />

NodePositionList class implement<strong>in</strong>g the node list<br />

ADT with a doubly l<strong>in</strong>ked list. (Cont<strong>in</strong>ues <strong>in</strong> Code<br />

Fragments 6.10 <strong>and</strong> 6.11.)<br />

337

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

Saved successfully!

Ooh no, something went wrong!