Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
Sender Ghost is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Key pressing with MINGW and Windows XP does not work
Next Topic: Problem using more classes...
Goto Forum:
  


Current Time: Sun Aug 24 19:00:16 CEST 2025

Total time taken to generate the page: 0.05317 seconds