home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1995 / ARCHIVE95.iso / discs / pipeline / 8_12 / Median / c_median next >
Text File  |  1995-07-15  |  792b  |  46 lines

  1. %OP%VS4.13 (28-Apr-92), Gerald L Fitton, R4000 5966 9904 9938 
  2. %OP%TNN
  3. %OP%DP2
  4. %OP%IRN
  5. %OP%PL55
  6. %OP%TM2
  7. %OP%HM2
  8. %OP%FM2
  9. %OP%BM2
  10. %OP%LM6
  11. %OP%FS0
  12. %OP%PT0
  13. %OP%WC2,1354,908,1748,0,0,0,0
  14. %OP%NDarow,B9
  15. %CO:A,66,0%
  16. %V%%L%function("median","list:array")
  17. \ return the median value from an unsorted list
  18.  
  19. \ sort the list
  20. %V%%L%[c_sort]sort(@list)
  21.  
  22. \ define and initialise 'local' variables
  23. %V%%L%set_name("arow",B9)
  24. %V%%L%set_value(arow,rows(A6))
  25.  
  26. %V%%L%repeat
  27. %V%%L%if(index(A6,1,arow)="",set_value(arow,arow-1),)
  28. %V%%L%until(index(A6,1,arow)>"")
  29.  
  30. \ odd number of items
  31. %V%%L%if(mod(arow,2)=1,result(index(A6,1,(arow+1)/2)),)
  32.  
  33. \ even number of items, find middle two and split the difference
  34. %V%%L%index(A6,1,arow/2)
  35. %V%%L%index(A6,1,arow/2+1)
  36. %V%%L%result((A20+A21)/2)
  37. %CO:B,12,0%
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. %V%%R%%D0%3
  46.