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. fthe stemplot ifstarts theat first stem value. #
# the data is assumed to be sorted into stem then leaf order #
PROC stem and leaf plot = ( []INT d, INT ffirst stem, PROC(INT)INT stem, leaf )VOID:
IF UPB d < LWB d THEN
print( ( "No data", newline ) )
ELSE
# there is some data to plot #
INT curr stem := f stem( d[ LWB d ] );
BOOLIF first stem < curr stem := TRUE;THEN
INTcurr this leafstem := leaf( d[ i ]first );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( this leaf( d[ i ] ), 0 ) ) )
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, -10, ( INT n )INT: n OVER 10, ( INT n )INT: n MOD 10 )
 
END
3,022

edits