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 details of our algorithm for add<strong>in</strong>g the new game entry e to the entries<br />

array are similar to this <strong>in</strong>formal description, <strong>and</strong> are given <strong>in</strong> <strong>Java</strong> <strong>in</strong> Code<br />

Fragment 3.3. Note that we use a loop to move references out of the way. The<br />

number of times we perform this loop depends on the number of references we<br />

have to move to make room for a reference to the new game entry. If there are 0,<br />

1, or even just a few references to move over, this add method will be pretty fast.<br />

But if there are a lot to move, then this method could be fairly slow. Also note<br />

that if the array is full <strong>and</strong> we perform an add on it, then we will either remove<br />

the reference to the current last game entry or we will fail to add a reference to the<br />

new game entry, e.<br />

Code Fragment 3.3:<br />

GameEntry object.<br />

<strong>Java</strong> code for <strong>in</strong>sert<strong>in</strong>g a<br />

146

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

Saved successfully!

Ooh no, something went wrong!