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