Compur. 8wl. Med. Vol. 13. Nu 4. pp. 299- 301. 1983. Printed in Great Britam
A POCKET
COIO-48?5/83 u.w+ a0 0 1983 Pergamon Press Ltd.
CALCULATOR
PROGRAM
TO SORT DATA
HENRIK E. POULSEN
Department of Medicine, Division of Hepatology, Rigshospitalet, 9, Blegdamsvej, DK-2100 Copenhagen, Denmark (Received 29 July 1982; in revised form 11 Nowmber 1982)
Abstract-A
program is presented for use with a TI59 calculator in sorting up to 98 data.
T159 calculator
Sorting
Ranking of biological data is an often required procedure. Ranking of a small number of data is readily performed by paper and pencil, but when the number of data increases it is desirable to leave the ranking to computers. The Texas Instruments T159 calculator with a statistical module is able to perform ranking as part of non parametrical statistical procedures, however, the maximal number of data it can sort is 60. A shell sorting programme, able to sort 99 data in about 9&n& is commercially available in the TI Math/Utilities Rom. A highly sophisticated fast shell sorting program which takes advantage of the hierachial registers of the TI-59 [l], and a program to alphabetic sort has been demonstrated [2]. The sorting program presented here, written for the T159, is able to sort 98 data. This number is the maximum number the T159 is able to sort by simple procedure since there are 100 registers and two are used for counters. The method used for ranking is straight forward. If N data are fed into the calculator it firstly finds the number with the highest numerical value and stores it in register N. Among the remaining N - 1 data it then finds the one with the highest value and stores it in register N - 1 and so on (steps 040-093). This method uses two counters and is fastest when the number of data is small. The computation time of a number of data can be read from Fig. 1. The speed of sorting is optimal, i.e. the program was first written by the use of labels; this program required 82 min to sort 98 data. Then the program was changed to only contain GOTO-statement and the time was reduced to 52 min for 98 data.
60
O0
20
40
60
Number of data to sort
80
1 I0
Fig. 1. Relation between the number of data and the time in minutes required to sort the data. The curve is based on the number of comparisons which for N numbers is 1 + 2 + 3 + + N. 299
HENRIK
300
E. POULSEN
Table 1. c 00 1 ljc; 0 1)z 004 OOf OOE 01:17 005 OOS Oli 0: 1 00
0 Is 101 I 014 Olf 016 01;
::f 02; 021 132; OZ’E 024 iJ2p 101s 027 02; 02C 03;
%9 UP 20 20 99 PRT 72 ST* 00 00 09 9 08 s 52 X:T 43 RCL y”7 ;; 11 68 68 31 81 76 10 72 “O cl@ 01 ‘94 44 00 69 c10 IO1 117 03 05
A NOP NDP R/S RST LEL E’ ST+ O 00 1 +.,SUM 00 OF 00 1 7 3 5
76
LBL
04; 04.:
04c 041
11 43 00
A RCL 00
:t! 04; 047 04s 040 05C 051
42 99 61 00 69 43 99 75
052
01 “5
STn 99 GTO 00 69 RCL 99 1 =
054 05f 05E
42 99 42
ST0 99 ST0
05i OSE 055
00 29 ‘2
00 ce
05:
06C 061 062 OE*Z IO64 0E.S 066 06;
071 072 07: 074 07’ 076 077 07; 079
INV 6: EQ 00 00 46 46 98 HDV 98 ADV 01 1 22 INV 913 LST
32 97 00 00 82 32 72 99 61
X:T DSZ 00 00 82 X:T ST* 99 CT0
’..3[
00
08i 081 08: 084 08’ Oat OS7 08E
;3’ :3’ 00 0 22 INV ;; $ 72 72 32 X:T
0
OGf 09c 041 09: 04
63 00 61 00
EX* 00 GTO 00
$34, ogj 09c
5; 15 98
L$E HD’V
:z: OUF 1OC 10 1 102 10: 104 105 106 107 1UE 109 11C 111 112 11: 114 115 116 117 11E 115
69 00 03 06 O? iI2 03 05 03 07 69 CG’ 69 05 98 69 00 01 06 01 03 03 07
OP 00 3 6 3 2 3 5 3 7 OP 02 IIP 05 ADV UP 00 1 6 1 3 3 7
12C 121 122 12: 124 12: 126 127 12E 125 13c 131 132 13: 134
01 03 69 Ul 03 05 06 03 03 06 69 02 69 05 47
1 3 UP 01 3 5 6 3 3 6 OP 02 OP 05 CMS
;;:. . 137 13:: :;‘;
29 25 98 ‘91 76 81
CLR 13P ADV R/S LBL RST
141 142 14’1
13 01 42
c 1 ST0
c :::’ 146
43 RCL lQO O0 00 100
::z 149 15C 151 152 15: 154 15’ 156 157 156 159
73 3?00 91 01 44 00 61 01 45 00 00 00
SllI;T DRTA
R,,S 12.354 10.547 9.125 7.256 5.123 8.589
5. 123 7.256 8.589 9.125 10.547 12.354
01 02 :: 05 06
::
0”: 09 10
0”: 0.
RC* ‘( Y’T 00 R/S 1 SUM 00 GTO 01 45 0 0 0
:: 0.
:: 13 14
:: -0. 0.
:z 17 18
The program is given in Table 1. Participation, initializing of registers and printing of instructions when the PC 1OOCis connected are in steps 096-140. The data are read and Table 2. Instructions to the user Procedure
Enter
Load program Initialize Data entry
1. DATA 2. DATA -
Data correction*
N.DATA
Sort Listing of sorted data4
Display sorted data
Press
Display
E
0
R/S R/S E’ -
1’ 2
R/S A
N3
0
SORT DATA R/S 1. DATA 2. DATA ERR N.DATA DATA 01 DATA 02 -_ DATA N
c x,rt R/S xjt
r The data can be displayed by changing line 012 and 013 to RC*OO ’ Deletes last data, unless No. 98 3 Branches to sorting procedure when N data is read 4 Only when PC IOOCis connected.
0 98 0 99 DATA RANK NEXT DATA RANK -
A pocket
calculator
program
to sort data
301
printed by the loop in steps Ooo-015, and the last datum is deleted by the subroutine ‘E (016-039). A print of the sorted data and their rank is performed in steps 065-067, and displayed by the subroutine C (143-158). User instructions are given in Table 2 together with a print of six data. It should be noted that the program gives the highest rank to the first of several identical data. If the sorting is used for transformation of the data for non parametrical statistical analysis, an appropriate correction for ties should be performed [3] or the rank value should be assigned at random. SUMMARY The T159 program presented is a sorting procedure which utilizes all the register capacity of the calculator. The time to sort 98 data is 52 min. The program is able to print instructions, input data, deletion of data and a list of the ranked data and their rank on a PC 1OOC printer, or can be used without the printer. REFERENCES I. Editor, TI PPC 52-notes V3N2 4, PPC Publications, P.O. Box 1421, Largo, FL 33540. 2. R. Snow, Tl PPC 52-notes V5N2 6, PPC Publications, P.O. Box 1421, Large, FL 33540. 3. S. Siegel, Nonparametric Statisticsfor the Behavioral Sciences. McGraw-Hill-Kogakusha, Tokyo (1956). FNKIK E. POULSEN was born in Aalborg, Denmark, in 1948. He studied medicine at Copenhagen University. He has been working on quantitation of liver functions for some years. At present he is a research fellow at the division of hepatology, Rigshospitalet, Copenhagen.
About the Author-H