home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- 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
- From: hjv@phil.ruu.nl (Hendrik Jan Veenstra)
- Subject: Re: is it possible to find max & next smallest in one pass?
- Message-ID: <hjv.727890482@groucho.phil.ruu.nl>
- Sender: news@phil.ruu.nl
- Nntp-Posting-Host: groucho.phil.ruu.nl
- Organization: Department of Philosophy, University of Utrecht, The Netherlands
- References: <1993Jan24.040702.6193@emr1.emr.ca> <51915@seismo.CSS.GOV>
- Date: Sun, 24 Jan 1993 15:48:02 GMT
- Lines: 39
-
- black@seismo.CSS.GOV (Mike Black) writes:
-
- >In article <1993Jan24.040702.6193@emr1.emr.ca> jagrant@emr1.emr.ca (John Grant) writes:
- >>Given an array of values, is it possible to find the maximum of
- >>the array and the next smallest value in a single pass? The reason
- >>I want it in one pass, is that the array is actually a data file
- >>of a million float values.
- >>
- >>If so, I guess the same single pass could also find the min and next
- >>highest value too?
- >>
-
- > for (i = 2; i < 1000; i++) {
- > value = random() / 1000.0;
- > ivalue(value > max1) { /* New max and demote old one */
- > max2 = max1;
- > max1 = value;
- > }
-
- And what if 'value' lies *between* max1 and max2...? Suppose you have to
- check for that too...
- So, supposing max1 is the biggest of the two, this would yield something like
-
- if (value > max1)
- {
- max2 = max1;
- max1 = value;
- }
- else if (value > max2)
- {
- max2 = value;
- }
-
-
- --
- Hendrik Jan Veenstra hjv@phil.ruu.nl * How can I save my dreams
- Dept. of Philosophy * in the nightmare, in the flood
- University of Utrecht * But I try.
- The Netherlands *
-