Stem-and-leaf plot: Difference between revisions
→{{header|ALGOL 68}}: tweak anf bugfix
(Added Algol 68) |
(→{{header|ALGOL 68}}: tweak anf bugfix) |
||
Line 242:
);
# generates a stem-and-leaf plot of d, the stems and leaves are derived #
# from the elements by stem and leaf.
# the data is assumed to be sorted into stem then leaf order #
PROC stem and leaf plot = ( []INT d, INT
IF UPB d < LWB d THEN
print( ( "No data", newline ) )
ELSE
# there is some data to plot #
INT curr stem :=
FI;
curr stem -:= 1;
BOOL first := TRUE;
FOR i FROM LWB d TO UPB d DO
INT this stem = stem( d[ i ] );
▲ INT this leaf = leaf( d[ i ] );
IF first OR curr stem /= this stem THEN
curr stem +:= 1;
Line 267 ⟶ 270:
OD
FI;
print( ( " ", whole(
OD
FI # stem and leaf plot # ;
Line 275 ⟶ 278:
QUICKSORT sorted data FROMELEMENT LWB sorted data TOELEMENT UPB sorted data;
# plot the data: stem = element / 10, leaf = element MOD 10 #
stem and leaf plot( sorted data,
END
|