home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / programm / 3572 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.8 KB  |  52 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!pmafire!news.dell.com!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!ruuinf!plato.phil.ruu.nl!hjv
  3. From: hjv@phil.ruu.nl (Hendrik Jan Veenstra)
  4. Subject: Re: is it possible to find max & next smallest in one pass?
  5. Message-ID: <hjv.727890482@groucho.phil.ruu.nl>
  6. Sender: news@phil.ruu.nl
  7. Nntp-Posting-Host: groucho.phil.ruu.nl
  8. Organization: Department of Philosophy, University of Utrecht, The Netherlands
  9. References: <1993Jan24.040702.6193@emr1.emr.ca> <51915@seismo.CSS.GOV>
  10. Date: Sun, 24 Jan 1993 15:48:02 GMT
  11. Lines: 39
  12.  
  13. black@seismo.CSS.GOV (Mike Black) writes:
  14.  
  15. >In article <1993Jan24.040702.6193@emr1.emr.ca> jagrant@emr1.emr.ca (John Grant) writes:
  16. >>Given an array of values, is it possible to find the maximum of
  17. >>the array and the next smallest value in a single pass?  The reason
  18. >>I want it in one pass, is that the array is actually a data file
  19. >>of a million float values.
  20. >>
  21. >>If so, I guess the same single pass could also find the min and next
  22. >>highest value too?
  23. >>
  24.  
  25. >    for (i = 2; i < 1000; i++) {
  26. >        value = random() / 1000.0;
  27. >        ivalue(value > max1) { /* New max and demote old one */
  28. >            max2 = max1;
  29. >            max1 = value;
  30. >        }
  31.  
  32. And what if 'value' lies *between* max1 and max2...?  Suppose you have to
  33. check for that too...
  34. So, supposing max1 is the biggest of the two, this would yield something like
  35.  
  36.          if (value > max1)
  37.          {
  38.             max2 = max1;
  39.             max1 = value;
  40.          }
  41.          else if (value > max2)
  42.          {
  43.             max2 = value;
  44.          }
  45.  
  46.  
  47. --
  48. Hendrik Jan Veenstra    hjv@phil.ruu.nl  *  How can I save my dreams
  49. Dept. of Philosophy                      *  in the nightmare, in the flood
  50. University of Utrecht                    *  But I try.
  51. The Netherlands                          *
  52.