finding low value in array 
Author Message
 finding low value in array

Is there a simple way to identify the highest and lowest values in an array of integer? Or is it necessary to do a sort and then take the first and last elements of the array?

----------

Chuck  Patch
Director of Systems
Historic New Orleans Collection

http://www.*-*-*.com/
(504)523-4662



Wed, 18 Jun 1902 08:00:00 GMT  
 finding low value in array

Quote:
> Is there a simple way to identify the highest and lowest values in an array of integer? Or is it necessary to do a sort and then take the first

and last elemen

   It depends on the data in it: if it's sorted, the values are at the
extreme ends of the array - you might want to sort the array first.  If
it's not sorted, it's only a matter of setting a "low" variable to the
maximum value and "high" variable to the lowest possible value - and
walking the array contents to find values which alter the initialized
values you set up.  Pretty standard stuff...



Wed, 18 Jun 1902 08:00:00 GMT  
 finding low value in array

: Is there a simple way to identify the highest and lowest values in
: an array of integer? Or is it necessary to do a sort and then take
: the first and last elements of the array?

Chuck:
  First, please limit your lines to <75 chars in length.
  To answer your question, consider the following pseudo-code

- Declare variables to hold the smallest and largest values.
- Initialize both values using the first element of the array.
- Have a loop search through the remainder of the array, comparing
    each element against the smallest and largest values.  If the
    current element value is larger than the largest, save it; if
    the current element value is smaller than the smallest, save it.
- Print out the two values.

Bob
--

+----------------------------------------------------------------------+
| Microsoft Network is prohibited from redistributing this work in any |
| form, in whole or in part without license.  License to distribute    |
| this work is available to Microsoft at $500.  Transmission without   |
| permission constitutes an agreement to these terms.                  |
|     Premission is hereby granted to duplicate this restriction.      |
+----------------------------------------------------------------------+



Wed, 18 Jun 1902 08:00:00 GMT  
 finding low value in array



Quote:
>> Is there a simple way to identify the highest and lowest values in an array of integer? Or is it necessary to do a sort and then take the first
>and last elemen

>   It depends on the data in it: if it's sorted, the values are at the
>extreme ends of the array - you might want to sort the array first.  If
>it's not sorted, it's only a matter of setting a "low" variable to the
>maximum value and "high" variable to the lowest possible value - and
>walking the array contents to find values which alter the initialized
>values you set up.  Pretty standard stuff...

One could also initialize them to the first value in the array.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 finding low value in array


Quote:

>Is there a simple way to identify the highest and lowest values in an array of integer? Or is it necessary to do a sort and then take the first and last elements of the array?

judging by your question, i'm assuming that the data is not already sorted.
just set two variables, high and low, to the first element in the array; walk
through the array starting from the second subscript to the end.  if the
current array value is greater than high, let high equal it; otherwise, if it's
lower than low, then let low equal it.  at the end, you'll have the highest and
lowest values.

you know, this seems like a homework problem. . .

salman.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. finding low value in arra

2. Compare 10 fields and return the lowest value ?

3. Search won't find lower case ?

4. Paradox style substring find (..Field Value..)

5. How do I finding the record with the max value in a Paradox table

6. How to find the value from Gen-Id()?

7. Finding value for a field

8. Finding the greatest DATE value in a table

9. Finding color from RGB values FAST

10. Algorithms for finding decimal values for Irrational numbers

11. Finding RGB values

12. Have someone any vcl component for finding(filtering) in database for entered value

 

 
Powered by phpBB® Forum Software