Computer Chess Club Archives


Search

Terms

Messages

Subject: Seeking an array index

Author: Antonio Senatore

Date: 05:43:45 01/04/05



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.