Home » Community » Newbie corner » array : minimum value
Re: array : minimum value [message #35631 is a reply to message #35624] |
Thu, 08 March 2012 12:31   |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello.
idkfa46 wrote on Wed, 07 March 2012 11:17 | There is an easier way to do it ?!
|
If you meant already defined functions to find minimum (maximum) value of the array, then there are two function templates from std and Upp namespaces (corresponding to STL and NTL (U++)), at least:
std::min_element (std::max_element),
Upp::MinElement (Upp::MaxElement).
#include <Core/Core.h>
CONSOLE_APP_MAIN {
int vec[] = { 5, 4, 3, 2, 1, 6, 7, 8, 9, 10 },
*Upp_value = Upp::MinElement(vec, vec + __countof(vec)),
*std_value = std::min_element(vec, vec + __countof(vec));
ASSERT(Upp_value == std_value);
Upp::Cout() << "Minimum value"
<< "\nUpp: " << *Upp_value
<< "\nstd: " << *std_value
<< "\n\nIndex of minimum value: " << Upp_value - vec << '\n';
}
[Updated on: Thu, 08 March 2012 12:40] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Aug 24 10:44:34 CEST 2025
Total time taken to generate the page: 0.04401 seconds
|