codepromo0.fr
MasterofProject

STL_ algorithm _ minimum and maximum values (min_element, max_element)

Label Minimum and maximum valuesMin_elementMax_elementSTL_ algorithmSTL
710 people read comments(0) Collection Report
Classification:

Primer C++ learning...

 

Simple record of my learning process (code based)


Min_element, max_element to find the minimum, maximum value. Very simple no big effect



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
Namespace STD using;

/*******************************************************************************************
<class ForwardIterator> template
Min_element ForwardIterator (first ForwardIterator, last ForwardIterator);

<class ForwardIterator class, Compare> template
Min_element ForwardIterator (first ForwardIterator, last ForwardIterator,
Comp Compare);

Eg:
<class ForwardIterator> template
Min_element ForwardIterator (first ForwardIterator, last ForwardIterator)
{
Lowest ForwardIterator = first;
If (first==last) last return;
While (++first! =last)
If (*first<*lowest) / or: if (COMP (*first, *lowest) for the comp version)
Lowest=first;
Lowest return;
}
********************************************************************************************/

/********************************************************************************************
<class ForwardIterator> template
Max_element ForwardIterator (first ForwardIterator, last ForwardIterator);

<class ForwardIterator class, Compare> template
Max_element ForwardIterator (first ForwardIterator, last ForwardIterator,
Comp Compare);
Eg:
<class ForwardIterator> template
Max_element ForwardIterator (first ForwardIterator, last ForwardIterator)
{
Largest ForwardIterator = first;
If (first==last) last return;
While (++first! =last)
If (*largest<*first) / or: if (COMP (*largest, *first) for the comp version)
Largest=first;
Largest return;
}
********************************************************************************************/

Myfn bool (I int, J int)
{
I<j return;
}

MyClass struct
{
Operator bool () (I int, J int)
{
I<j return;
}
} myobj;

Main int ()
{
Myints[] int = {3,7,2,5,6,4,9};

Default comparison: / / using
Cout "smallest element is The" "*min_element (myints, myints+7)" endl;
Cout "largest element is The" "*max_element (myints, myints+7)" endl;

Using function myfn as / / comp: function
Cout "smallest element is The" "*min_element (myints, myints+7, myfn)" endl;
Cout "largest element is The" "*max_element (myints, myints+7, myfn)" endl;

Object myobj / / using as function of the comp: object
Cout "smallest element is The" "*min_element (myints, myints+7, myobj)" endl;
Cout "largest element is The" "*max_element (myints, myints+7, myobj)" endl;

Return 0;
}

/*********
Output:
Smallest element is The 2
Largest element is The 9
Smallest element is The 2
Largest element is The 9
Smallest element is The 2
Largest element is The 9
*********/


top
Zero
tread
Zero
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • Visit90909 times
    • Integral:Two thousand seven hundred and two
    • Grade
    • Rank:7623rd name
    • Original265
    • Reproduced:11
    • Translation:1
    • Comments:72
    Welcome to my blog.
    Http://home.cnblogs.com/ing/
    Blog column
    Music heaven and earth

    Latest comments
gutscheincode0.de