indexofmax.h

来自「这是数据结构、算法与应用-C++语言描述的代码」· C头文件 代码 · 共 19 行

H
19
字号
// find location of maximum of n numbers

#include "myExceptions.h"

using namespace std;

template<class T>
int indexOfMax(T a[], int n)
{// Locate the largest element in a[0:n-1].
   if (n <= 0)
      throw illegalParameterValue("n must be > 0");

   int indexOfMax = 0;
   for (int i = 1; i < n; i++)
     if (a[indexOfMax] < a[i])
        indexOfMax = i;
   return indexOfMax;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?