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.

We show an example output from a run of the Duck, Duck, Goose program <strong>in</strong><br />

Figure 3.20.<br />

Figure 3.20: Sample output from the Duck, Duck,<br />

Goose program.<br />

Note that each iteration <strong>in</strong> this particular execution of this program produces a<br />

different outcome, due to the different <strong>in</strong>itial configurations <strong>and</strong> the use of<br />

r<strong>and</strong>om choices to identify ducks <strong>and</strong> geese. Likewise, whether the "Duck" or the<br />

"Goose" w<strong>in</strong>s the race is also different, depend<strong>in</strong>g on r<strong>and</strong>om choices. This<br />

execution shows a situation where the next child after the "it" person is<br />

immediately identified as the "Goose," as well a situation where the "it" person<br />

walks all the way around the group of children before identify<strong>in</strong>g the "Goose."<br />

Such situations also illustrate the usefulness of us<strong>in</strong>g a circularly l<strong>in</strong>ked list to<br />

simulate circular games like Duck, Duck, Goose.<br />

3.4.2 Sort<strong>in</strong>g a L<strong>in</strong>ked List<br />

186

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

Saved successfully!

Ooh no, something went wrong!