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.

header nor do we show the null next po<strong>in</strong>ter for the<br />

trailer.<br />

Insert<strong>in</strong>g or remov<strong>in</strong>g elements at either end of a doubly l<strong>in</strong>ked list is straightforward<br />

to do. Indeed, the prev l<strong>in</strong>ks elim<strong>in</strong>ate the need to traverse the list to get to<br />

the node just before the tail. We show the removal at the tail of a doubly l<strong>in</strong>ked list<br />

<strong>in</strong> Figure 3.15 <strong>and</strong> the details for this operation <strong>in</strong> Code Fragment 3.18.<br />

Figure 3.15: Remov<strong>in</strong>g the node at the end of a a<br />

doubly l<strong>in</strong>ked list with header <strong>and</strong> trailer sent<strong>in</strong>els: (a)<br />

before delet<strong>in</strong>g at the tail; (b) delet<strong>in</strong>g at the tail; (c)<br />

after the deletion.<br />

Code Fragment 3.18: Remov<strong>in</strong>g the last node of a<br />

doubly l<strong>in</strong>ked list. Variable size keeps track of the<br />

current number of elements <strong>in</strong> the list. Note that this<br />

method works also if the list has size one.<br />

172

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

Saved successfully!

Ooh no, something went wrong!