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.

example, when pundits study political speeches look<strong>in</strong>g for themes. A hash table is<br />

an ideal data structure to use here, for we can use words as keys <strong>and</strong> word counts as<br />

values. We show such an application <strong>in</strong> Code Fragment 9.6.<br />

Code Fragment 9.6: A program for count<strong>in</strong>g word<br />

frequencies <strong>in</strong> a document, pr<strong>in</strong>t <strong>in</strong>g the most frequent<br />

word. The document is parsed us<strong>in</strong>g the Scanner class,<br />

for which we change the delimiter for separat<strong>in</strong>g tokens<br />

from whitespace to any non letter. We also convert<br />

words to lowercase.<br />

543

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

Saved successfully!

Ooh no, something went wrong!