 TechArena Community Implement the min_element() in programming of C++

#1
 Garrick Member Join Date: Dec 2009 Posts: 26
Implement the min_element() in programming of C++

I am the student of the Bsc-CS. I must have to submit the assignment on the functions of the C++ library in four days. I could also had the well knowledge of the functions that could be used in the C++ programming language. Even though, I could not know much more about the min_element() function of the C++ programming language. So, I would like to know about the min_element() function of the C++ programming language. I also would like to know How to Implement the min_element() in C++ coding. Reply Me!!
#2
 Reegan Member Join Date: Oct 2005 Posts: 2,389
The min_element() in programming of C++

The min_element() function can returns an iterator to the smallest element in the given specified range as [strt,nd). If the predicate variable of the binary s can be given then min_element() function can be used in spite of the less than "<" operator to decide the an element that can be smallest. The following can be the syntax of the min_element() function :
Code:
```template <class FrwrdItrtr>
FrwrdItrtr min_element ( FrwrdItrtr fst, FrwrdItrtr lst );```
#3
 opaper Member Join Date: May 2008 Posts: 2,383
The min_element()

The following can be the parameters of the min_element() function in the C++ language :
1. cmp : This parameter of the min_element() function can contains an object of the comparison function that can takes two values of the similar type than those can consisted in the given specified range. The min_element() function can returns true value if the first argument can be considered less than the second argument and else returns the false value.
2. fst, lst : These parameters of the min_element() function can contains an input iterators to the final and the starting positions of the given specified sequence to use. The range used that can be as [fst,lst).
__________________
The FIFA Manager 2009 PC Game
#4
 MindSpace Member Join Date: Feb 2008 Posts: 1,848
min_element() in programming of C++

PROGRAM :
Code:
```#include <iostream>
#include <algorithm>
using namespace std;
bool mf(int a, int b)
{
return a<b;
}
struct mcls
{
bool operator() (int a,int b)
{
return a<b;
}
} moj;
int main ()
{
int ms[] = {3,7,2,5,6,4,9};
cout << "The smallest element is " << *min_element(ms,ms+7) << endl;
cout << "The largest element is " << *max_element(ms,ms+7) << endl;
cout << "The smallest element is " << *min_element(ms,ms+7,mf) << endl;
cout << "The largest element is " << *max_element(ms,ms+7,mf) << endl;
cout << "The smallest element is " << *min_element(ms,ms+7,moj) << endl;
cout << "The largest element is " << *max_element(ms,ms+7,moj) << endl;
return 0;
}```
Output:
Code:
```The smallest element is 2
The largest element is 9
The smallest element is 2
The largest element is 9
The smallest element is 2
The largest element is 9```
The example can demonstrates you how an object of the comparison can be either an object or a function whose class can be defines an operator() function member. In this case both can be defined to execute a standard less-than comparison.
#5
 Modifier Member Join Date: Jan 2008 Posts: 1,515
Re: Implement the min_element() in programming of C++

The min_element() function can returns an iterator that can be pointing to an element with the value that can be smallest in the given specified range as [fst,lst). The behavior of min_element() function template can be similar to the following as :
Code:
```template <class FrwrdItrtr>
FrwrdItrtr min_element ( FrwrdItrtr fst, FrwrdItrtr lst )
{
FrwrdItrtr lwst = fst;
if (fst==lst) return lst;
while (++fst!=lst)
if (*fst<*lwst)
lwst=fst;
return lwst;
}```
#6
 Praetor Member Join Date: Apr 2008 Posts: 1,948
Re: Implement the min_element() in programming of C++

Here can be the one more example on the min_element() function of the C++ language and the following program can help's you to learn the min_element() function :
Code:
```#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> cl;
vector<int>::iterator ps;
cl.psh_bck(2);
cl.psh_bck(5);
cl.psh_bck(4);
cl.psh_bck(1);
cl.psh_bck(6);
cl.psh_bck(3);
ps = min_element (cl.begin(), cl.end());
cout << "min: " << *ps << endl;
}```
The output of the above program :
Code:
`min: 1`

 Tags:

 Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Similar Threads for: "Implement the min_element() in programming of C++" Thread Thread Starter Forum Replies Last Post Help me to implement the partition() function in the C++ language programming Gavyn Software Development 5 25-02-2010 03:35 PM Implement the rotate() in the CPP programming Rajeev D Software Development 5 23-02-2010 05:30 PM How to implement IP Sec Enriquee Technology & Internet 5 12-01-2010 06:28 AM Socket programming: Is any new Programming Language? Kushan Software Development 3 14-11-2009 11:13 AM JetBrains Introduces a New Programming Paradigm With its Meta Programming System JoeFrat Software Development 3 13-12-2008 01:49 PM

All times are GMT +5.5. The time now is 06:09 PM.