home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / programm / 3587 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1008 b   |  31 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!utcsri!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel
  3. From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel)
  4. Subject: Re: is it possible to find max & next smallest in one pass?
  5. Message-ID: <1993Jan25.173848.6062@alchemy.chem.utoronto.ca>
  6. Organization: Department of Chemistry, University of Toronto
  7. References: <1993Jan24.040702.6193@emr1.emr.ca> <1jt96b$kc9@agate.berkeley.edu>
  8. Date: Mon, 25 Jan 1993 17:38:48 GMT
  9. Lines: 20
  10.  
  11. In article <1jt96b$kc9@agate.berkeley.edu> bsmith@mickey.NoSubdomain.NoDomain
  12. (Brian Smith) writes:
  13. >/* Keep max2 >= max1 */
  14. >max1 = max2 = x[0];
  15. >for (i=1; i<N; i++) {
  16. >    if (x[i] > max1) {
  17. >    if (x[i] > max2) {
  18. >        max1 = max2;
  19. >        max2 = x[i];
  20. >    } else {
  21. >        max1 = x[i];
  22. >    } 
  23. >    }
  24. >}
  25. >/* At this point, max2 is largest, min1 is next largest */
  26.  
  27.      The initialization is dangerous.  What if x[0] is the largest value?
  28.  
  29.                 Marc R. Roussel
  30.                                 mroussel@alchemy.chem.utoronto.ca
  31.