Anonymous user
Stem-and-leaf plot: Difference between revisions
m
→{{header|REXX}}: elided some statements in the program, changed whitespace and comments.
(→{{header|Julia}}: A new entry for Julia) |
m (→{{header|REXX}}: elided some statements in the program, changed whitespace and comments.) |
||
Line 1,981:
<br>Also, all numbers that are processed are normalized.
<br>Using a sparse array bypasses the need for sorting.
<lang rexx>/*REXX program displays a
if data='' then data=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31,
max= /* ··· and decimal fractions. */▼
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
117 116 27
57 122 109
parse var data min . 1 max . '' #. /*define MIN & MAX as 1st number.*/
do j=1 for words(data); _=format(word(data,j),,0)/1 /*normalize*/
stem=left(_, max(1, length(_)-1)) /*extract the stem from the num. */
if length(_)==1 then stem=0 /*handle
▲ leaf=right(_,1) /*pick off the leaf from the num.*/
#.stem.leaf=#.stem.leaf leaf /*construct a sorted stem-&-leaf.*/
end /*j*/
w=max(length(min), length(max))
do k=min to max; _=; do m=0 for 10;
say right(k,w) '
end /*k*/
/*stick a fork in it, we're done.*/</lang>
'''output''' when using the default input:
<pre>
10
11
12
13
14
</pre>
|