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.

Likewise, we can easily perform an <strong>in</strong>sertion of a new element at the beg<strong>in</strong>n<strong>in</strong>g of a<br />

doubly l<strong>in</strong>ked list, as shown <strong>in</strong> Figure 3.16 <strong>and</strong> Code Fragment 3.19.<br />

Figure 3.16: Add<strong>in</strong>g an element at the front: (a)<br />

dur<strong>in</strong>g; (b) after.<br />

Code Fragment 3.19: Insert<strong>in</strong>g a new node v at the<br />

beg<strong>in</strong>n<strong>in</strong>g of a doubly l<strong>in</strong>ked list. Variable size keeps<br />

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

that this method works also on an empty list.<br />

173

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

Saved successfully!

Ooh no, something went wrong!