24.01.2014 Views

Arrays

Arrays

Arrays

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.

Histogram<br />

Type the weights (0-199). One weight per line. End with -1.<br />

13<br />

12.3<br />

82.4<br />

12.9<br />

...<br />

-1<br />

Weight : Frequency<br />

...<br />

10 : ***<br />

11 : *<br />

12 : **<br />

...<br />

82 : *<br />

83 :<br />

...<br />

199 : *****<br />

Data structure:<br />

• An array is used to count the weights.<br />

• Index in the array represents a weight group.<br />

• Value of an element in the array represents the number of<br />

children in this weight group, i.e. the frequency.<br />

Algorithm:<br />

- Read the weights and place them in the correct weight group.<br />

- Find the minimum and the maximum weight register.<br />

- For each weight group (from minimum to maximum) print the<br />

number of stars that represent the frequency.

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

Saved successfully!

Ooh no, something went wrong!