home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!utcsri!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel
- From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel)
- Subject: Re: is it possible to find max & next smallest in one pass?
- Message-ID: <1993Jan25.173848.6062@alchemy.chem.utoronto.ca>
- Organization: Department of Chemistry, University of Toronto
- References: <1993Jan24.040702.6193@emr1.emr.ca> <1jt96b$kc9@agate.berkeley.edu>
- Date: Mon, 25 Jan 1993 17:38:48 GMT
- Lines: 20
-
- In article <1jt96b$kc9@agate.berkeley.edu> bsmith@mickey.NoSubdomain.NoDomain
- (Brian Smith) writes:
- >/* Keep max2 >= max1 */
- >max1 = max2 = x[0];
- >for (i=1; i<N; i++) {
- > if (x[i] > max1) {
- > if (x[i] > max2) {
- > max1 = max2;
- > max2 = x[i];
- > } else {
- > max1 = x[i];
- > }
- > }
- >}
- >/* At this point, max2 is largest, min1 is next largest */
-
- The initialization is dangerous. What if x[0] is the largest value?
-
- Marc R. Roussel
- mroussel@alchemy.chem.utoronto.ca
-