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.

the last element. That is, it uses a list cursor, much like a screen cursor is viewed as<br />

be<strong>in</strong>g located between two characters on a screen. Specifically, the<br />

java.util.ListIterator <strong>in</strong>terface <strong>in</strong>cludes the follow<strong>in</strong>g methods:<br />

add(e):<br />

Add the element e at the current position of the iterator.<br />

hasNext():<br />

True if <strong>and</strong> only if there is an element after the current position of the<br />

iterator.<br />

hasPrevious():<br />

True if <strong>and</strong> only if there is an element before the current position of the<br />

iterator.<br />

previous():<br />

Return the element e before the current position <strong>and</strong> sets the current<br />

position to be before e.<br />

next():<br />

Return the element e after the current position <strong>and</strong> sets the current position<br />

to be after e.<br />

nextIndex():<br />

Return the <strong>in</strong>dex of the next element.<br />

previousIndex():<br />

Return the <strong>in</strong>dex of the previous element.<br />

set(e):<br />

Replace the element returned by the previous next or previous operation<br />

with e.<br />

remove():<br />

Remove the element returned by the previous next or previous operation.<br />

It is risky to use multiple iterators over the same list while modify<strong>in</strong>g its contents. If<br />

<strong>in</strong>sertions, deletions, or replacements are required at multiple "places" <strong>in</strong> a list, it is<br />

safer to use positions to specify these locations. But the<br />

java.util.L<strong>in</strong>kedList class does not expose its position objects to the user.<br />

347

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

Saved successfully!

Ooh no, something went wrong!