Hi,
I have six arrays which is of float type. Any specific index in all these arrays represent set of values for me. Ex: if index is zero all the six arrays zeroth index represent a set of values, from which i need to find the max value. similarly for all other indexes.
array1 array2 array3 array4 array5 array6
0 0 0 0 0 0
1 1 1 1 1 1
-------------------------------------so on
i need to find out which is the max value of a specific index among all these arrays and should store it in another array or list
Loading

VulpesRank #55 · 29.2K reputationPosted Aug 25, 2011, 5:20 AM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Aug 25, 2011, 5:11 AM EDT
Store those specific index values in one array and compare that array value.
Suthish NairRank #92 · 22.8K reputationPosted Aug 25, 2011, 7:47 AM EDT
Sam HobbsRank #108 · 20.5K reputationPosted Aug 25, 2011, 9:17 AM EDT
Is this a class assignment? It sure sounds like one.
You might consider making a two-dimensional array and then you can use existing methods to access the set of values instead of writing a line of code for each one of the six values.
Sam HobbsRank #108 · 20.5K reputationPosted Aug 25, 2011, 9:21 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 25, 2011, 9:39 AM EDT
The only ones I'm reasonably fluent in nowadays are C#, C++ and VB though I have used several others in my time.
Sam,
Judging by the OP's previous thread, he's using C++/CLI.
Sam HobbsRank #108 · 20.5K reputationPosted Aug 25, 2011, 10:33 AM EDT
Also for C++ the Boost web site has an abundance of additional classes that can help. The Boost web site says that ten of the Boost libraries are in the new C++ standard. So it is likely that it is possible to use a library that is even more mature than the existing C++ Standard Library to write code now that will be compatible with the new standard.
VulpesRank #55 · 29.2K reputationPosted Aug 25, 2011, 11:15 AM EDT
Here's the C++/CLI code for that:
#include "stdafx.h"
using namespace System;
array
{
array
for(int i = 0; i < array2D->GetLength(0); i++)
{
float max = Single::MinValue;
for(int j = 0; j < array2D->GetLength(1); j++)
{
if (array2D[i, j] > max) max = array2D[i, j];
}
maxima[i] = max;
}
return maxima;
}
int main(array
{
array
{
{1, 2, 3, 4, 5, 6},
{7, 8, 9, 1, 2, 3},
{1, 2, 3, 10, 11, 12},
{-1, -2, -3, -4,-5, -6},
{-7, -8, -9, -3, -4, -5},
{4, 5, 6, -1, -2, -3}
};
array
// check it worked
Console::WriteLine("The maxima are \n");
for each(float f in maxima) Console::WriteLine(f);
Console::ReadKey();
return 0;
}
VulpesRank #55 · 29.2K reputationPosted Aug 26, 2011, 6:31 AM EDT