Median of Statistics Data
This section contains three programs:
• SORT orders the elements of a list.
• LMED calculates the median of a sorted list.
• MEDIAN uses SORT and LMED to calculate the median of the cur-
rent statistics data.
SORT (Sort a List)
Sort a list into ascending order.
• Bubble sort. Starting with the first and second numbers in the list,
SORT compares adjacent numbers and moves the larger number
toward the end of the list. This process is done once to move the
largest number to the last position in list, then again to move the
next largest to the next-to-Iast position, and so on.
• Nested definite loops. The outer loop controls the stopping position
each time the process is done; the inner loop runs from 1 to the
stopping position each time the process is done.
• Nested local-variable structures. SORT contains two local-variable
structures, the second inside the defining program of the first. This
nesting is done for convenience; it's easier to create the first local
variable as soon as its value is computed, thereby removing its
value from the stack, rather than computing both values and creat-
ing both local variables at once.
28: Programming Examples