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.

Figure 3.12: Insertion at the tail of a s<strong>in</strong>gly l<strong>in</strong>ked list:<br />

(a) before the <strong>in</strong>sertion; (b) creation of a new node; (c)<br />

after the <strong>in</strong>sertion. Note that we set the next l<strong>in</strong>k for<br />

the tail <strong>in</strong> (b) before we assign the tail variable to<br />

po<strong>in</strong>t to the new node <strong>in</strong> (c).<br />

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

end of a s<strong>in</strong>gly l<strong>in</strong>ked list. This method works also if<br />

the list is empty. Note that we set the next po<strong>in</strong>ter for<br />

the old tail node before we make variable tail po<strong>in</strong>t to<br />

the new node.<br />

3.2.2 Remov<strong>in</strong>g an Element <strong>in</strong> a S<strong>in</strong>gly L<strong>in</strong>ked List<br />

168

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

Saved successfully!

Ooh no, something went wrong!