indexofmax.cpp

来自「datastucutre and algorithms, application」· C++ 代码 · 共 24 行

CPP
24
字号
// find location of maximum of n numbers

#include <iostream>
#include <algorithm> // has copy
#include "indexOfMax.h"

using namespace std;

int main()
{
   int a[6] = {1, 4, 2, 5, 6, 3};

   // output the array elements
   cout << "a[0:5] = ";
   copy(a, a+6, ostream_iterator<int>(cout, " "));
   cout << endl;

   // test the function indexOfMax
   cout << "max(a,1) = " << a[indexOfMax(a,1)] << endl;
   cout << "max(a,3) = " << a[indexOfMax(a,3)] << endl;
   cout << "max(a,6) = " << a[indexOfMax(a,6)] << endl;
   return 0;
}

⌨️ 快捷键说明

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