Stem-and-leaf plot: Difference between revisions
→{{header|ALGOL 68}}: replace as to not depend on some random guy's utility library. if the code is needed for the solution, it should be explicitly in it. This solution avoids sorting altogether.
(→{{header|ALGOL 68}}: tweak anf bugfix) |
(→{{header|ALGOL 68}}: replace as to not depend on some random guy's utility library. if the code is needed for the solution, it should be explicitly in it. This solution avoids sorting altogether.) |
||
Line 224:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<syntaxhighlight lang="algol68">
BEGIN
# get lower and higher stem value #
INT min stem := data[LWB data] % 10,
[]INT data = ( 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44▼
, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139▼
, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117▼
, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41▼
, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121▼
IF max stem < stem THEN max stem := stem FI
, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141▼
OD;
, 46, 13, 27, 43, 117, 116, 27, 7, 68, 40, 31▼
# this array will store the amount of leaves per stem: #
, 115, 124, 42, 128, 52, 71, 118, 117, 38, 27, 106▼
[min stem : max stem, 0:9]INT stems;
, 33, 117, 116, 111, 40, 119, 47, 105, 57, 122, 109▼
FOR i FROM LWB stems TO UPB stems DO
, 124, 115, 43, 120, 43, 27, 27, 18, 28, 48, 125▼
# fill the array #
FOR i FROM LWB data TO UPB data DO
stems[data[i] % 10, data[i] %* 10] +:= 1
OD;
# print the histogram #
FOR i FROM LWB stems TO UPB stems DO
print( ( "No data", newline ) )▼
print((whole(i, -4), "|
print(REPR (j + ABS "0")
OD;
END;▼
▲ curr stem -:= 1;
▲ FOR i FROM LWB d TO UPB d DO
▲ INT this stem = stem( d[ i ] );
▲ OD
▲ FI # stem and leaf plot # ;
stem and leaf plot(data)
▲END
</syntaxhighlight>
{{out}}
<pre>
0|
1|
2|
3| 011112345677789
4| 001222233344456788
5|
6|
7| 1
8|
9|
10|
11| 13333444555666677778899
12| 00112234445556777788
13|
14|
</pre>
|