Visual c++ 最大值包含的向量的位置
有人能帮我找到向量的最大值所在的位置吗。我使用Visual C++。Visual c++ 最大值包含的向量的位置,visual-c++,vector,arraylist,Visual C++,Vector,Arraylist,有人能帮我找到向量的最大值所在的位置吗。我使用Visual C++。 std::vector<double> array; 最大值为59.3。我想填充它的位置 max_location = 3; 有没有办法得到它。。。?请帮帮我 好吧,让我们想一想。你想一个接一个地遍历向量,找到最大值;您希望跟踪值的索引。下面是一些伪代码: index = 0 for each value in the array from 0 to end if this is the highe
std::vector<double> array;
最大值为59.3。我想填充它的位置
max_location = 3;
有没有办法得到它。。。?请帮帮我 好吧,让我们想一想。你想一个接一个地遍历向量,找到最大值;您希望跟踪值的索引。下面是一些伪代码:
index = 0
for each value in the array from 0 to end
if this is the highest value you've seen so far
save value
save index of value
print index
<>你怎么能在C++中做这些? 因为这是一个家庭作业,我不会发布完整的解决方案,只是一个想法。以std::max_元素为例。它返回一个迭代器,如果它不等于您的array.end,您可以得到它和array.begin之间的距离,这将是您要查找的索引
index = 0
for each value in the array from 0 to end
if this is the highest value you've seen so far
save value
save index of value
print index