Hi guys. I think my question is pretty simple.
What is the best way of making element-wise max operation on two std::array s in c++?
Example:
array1 = {4,5,3,2,1,7}
array2 = {3,4,2,6,7,1}
array3 = max(array1,array2);
then
array3 = {4,5,3,6,7,7}
Thanks,
Dario
Make a function that accepts 3 arrays.
1 2 3 4 5 6 7
|
for every i from 0 to SIZE
if array1[i] > array2[i]
// do something
else if array1[i] < array2[i]
// do something
else // do something
end for-loop
|
Translate pseudo-code to c++ and fill in the missing pieces.
Last edited on
1 2
|
std::transform (array1, array1 + size, array2,
std::back_inserter(result), std::greater<int> {});
|
Last edited on