home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1995
/
ARCHIVE95.iso
/
discs
/
pipeline
/
8_12
/
Median
/
c_median
next >
Wrap
Text File
|
1995-07-15
|
792b
|
46 lines
%OP%VS4.13 (28-Apr-92), Gerald L Fitton, R4000 5966 9904 9938
%OP%TNN
%OP%DP2
%OP%IRN
%OP%PL55
%OP%TM2
%OP%HM2
%OP%FM2
%OP%BM2
%OP%LM6
%OP%FS0
%OP%PT0
%OP%WC2,1354,908,1748,0,0,0,0
%OP%NDarow,B9
%CO:A,66,0%
%V%%L%function("median","list:array")
\ return the median value from an unsorted list
\ sort the list
%V%%L%[c_sort]sort(@list)
\ define and initialise 'local' variables
%V%%L%set_name("arow",B9)
%V%%L%set_value(arow,rows(A6))
%V%%L%repeat
%V%%L%if(index(A6,1,arow)="",set_value(arow,arow-1),)
%V%%L%until(index(A6,1,arow)>"")
\ odd number of items
%V%%L%if(mod(arow,2)=1,result(index(A6,1,(arow+1)/2)),)
\ even number of items, find middle two and split the difference
%V%%L%index(A6,1,arow/2)
%V%%L%index(A6,1,arow/2+1)
%V%%L%result((A20+A21)/2)
%CO:B,12,0%
%V%%R%%D0%3