Author: Klaus Friedel
Date: 10:52:58 01/04/05
Go up one level in this thread
It might be faster to not search the array at all.
Use two additional variables:
int max, maxIndex;
Each time you update any of the array entries you need
to compare the new entry with max and update
max and maxIndex if it's greater.
Regards,
Klaus
P.S.: Sorry for the preceeding empty message...
On January 04, 2005 at 08:43:45, Antonio Senatore wrote:
>
>Hi friends:
>
>I need to find the index of the highest value in an array of N integer positive
>numbers. Does anyone know a faster algorithm than the following:
>
>int find_index (int *arr, int N) {
>
> int best_val = -INF, i, index;
>
> for (i = 0; i < N; i++) {
> if (arr[i] > best_val) {
> index = i;
> best_val = arr[i];
> }
> }
> return index;
>}
>
>Thank you very much in advance
>Antonio
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.