C ++函数查找在双打的数组最大值? [英] C++ function to find max value in an array of doubles?

查看:105
本文介绍了C ++函数查找在双打的数组最大值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现自己写,通过我喜欢使用这些函数的图形显示之前数据标准化double数组中搜索最大值功能。

I frequently find myself writing max value functions that search through an array of doubles I use functions like these to normalize data before graphic display.

有没有更好的方式来寻找双打的数组的最大价值?有没有找到一个数组的最大值一个标准的功能?是否有某种内在此操作?我记得在DSP芯片中存在专门的ASM指令。

Is there a better way to find the max value of an array of doubles? Is there a standard function to find the max value in an array? Are there some intrinsic for this operation? I remember specialized ASM instruction existed in DSP chips.

推荐答案

是的!有一个名为的std :: max_element 功能:

Yep! There's a function called std::max_element:

double arr[LENGTH] = /* ... */
double max = *std::max_element(arr, arr + LENGTH);

您需要的#include<&算法GT; 来做到这一点。这头有一大堆在里面好吃的东西,它是值得花时间去了解更多的STL容器和算法库,因为它们可以让你的生活的这样的容易多了。

You'll need to #include <algorithm> to do this. That header has a whole bunch of goodies in it, and it's worth taking the time to learn more about the STL containers and algorithms libraries, as they can make your life so much easier.

只要我们关于这个问题,可以考虑寻找到的std ::矢量的std ::阵列作为替代原料C ++的数组。他们是安全的,有点更容易使用。

As long as we're on the subject, consider looking into std::vector or std::array as replacements for raw C++ arrays. They're safer and a bit easier to use.

希望这有助于!

这篇关于C ++函数查找在双打的数组最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆