|
| |||||||||
| Tags: adjacent_find, algorithm, cpp, functions, library |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Help me to implement adjacent_find() in C++
Hi All, i can have the good knowledge of the C++ language. I had also created the project on the C++ language. But I can not know much more about the functions of C++ language. So, I want to know about the adjacent_find() function. I also want to know about how can I implement the adjacent_find() function in the C++ language. Thus, If you can have the answer for my query then reply me. |
|
#2
| ||||
| ||||
| The adjacent_find() in C++
Hello, The adjacent_find() function can be used to search between end and start for two of the element that can be the similar relatively. If the predicate of the binary can be defined in the adjacent_find() function, then adjacent_find() function cam be used for to check that if two elements can be the similar or not. I think it could be enough for you to know about the adjacent_find() function in C++ language.
__________________ Grand Theft Auto 4 PC Video Game |
|
#3
| ||||
| ||||
| Implement adjacent_find() in C++
The following code of lines can help's you to learn adjacent_find() function more quickly and effectively : Code: #include <vector>
#include <algorithm>
#include <iostream.h>
int main()
{
typedef vector<int>::iterator iterator;
int e1[10] = {0,1,2,2,3,4,2,2,6,7};
vector<int> w1(e1,e1 + 10);
iterator itr1 = find(w1.begin(),w1.end(),3);
iterator itr2 =
find_if(w1.begin(),w1.end(),bine1st(equal_to<int>(),3));
iterator itr3 = adjacent_find(w1.begin(),w1.end());
iterator itr4 =
adjacent_find(w1.begin(),w1.end(),equal_to<int>());
cout << *itr1 << " " << *itr2 << " " << *itr3 << " "
<< *itr4 << endl;
return 0;
} Code: 3 3 2 2
__________________ The FIFA Manager 2009 PC Game |
|
#4
| ||||
| ||||
| adjacent_find() in C++ Program : Code: #jnclude <vector>
#jnclude <algorjthm>
#jnclude <functjonal>
#jnclude <jostream>
jnt majn ()
{
vector<jnt> w1;
for( jnt j = 0; j < 10; j++ )
{
w1.push_back(j);
jf( j == 7 )
{
w1.push_back(j);
}
}
vector<jnt>::jterator result;
result = adjacent_fjnd( w1.begjn(), w1.end() );
jf( result == w1.end() )
{
cout << "Djd not fjnd adjacent elements jn w1" << endl;
}
else
{
cout << "Found matchjng adjacent elements startjng at " << *result <<
endl;
}
} |
|
#5
| ||||
| ||||
| adjacent_find()
In C++ language, The following can be the general syntax of the adjacent_find() function : Code: #include <algorithm>
forward_iterator adjacent_find( forward_iterator start,
forward_iterator end );
forward_iterator adjacent_find( forward_iterator start,
forward_iterator end, BinPred pr ); |
|
#6
| ||||
| ||||
| Help me to implement adjacent_find() in C++
The adjacent_find() function can search the first two elements with same values. For example : Code: #include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
template <class T>
inline void PRINTELMENTS (const T& col, const char* optcsr="")
{
typename T::constiterator ps;
std::cout << optcsr;
for (ps=col.begin(); ps!=col.end(); ++ps)
{
std::cout << *ps << ' ';
}
std::cout << std::endl;
}
template <class T>
inline void INSERTELEMENTS (T& col, int fst, int lst)
{
for (int j=fst; j<=lst; ++j)
{
col.insert(col.end(),j);
}
}
bool doubled (int elm1, int elm2)
{
return elm1 * 2 == elm2;
}
int main()
{
vector<int> col;
col.pushback(1);
col.pushback(3);
col.pushback(2);
col.pushback(4);
col.pushback(5);
col.pushback(5);
col.pushback(0);
PRINTELEMENTS(col,"col: ");
vector<int>::iterator ps;
ps = adjacent_find (col.begin(), col.end());
if (ps != col.end())
{
cout << "first two elements with equal value have position "
<< distance(col.begin(),ps) + 1
<< endl;
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Help me to implement adjacent_find() in C++" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to implement and use ipfilter.dat | Roockie | Windows Software | 4 | 25-06-2010 06:28 AM |
| How to implement the front() in C++ | Ranjar | Software Development | 5 | 15-03-2010 04:55 PM |
| How to implement IP Sec | Enriquee | Technology & Internet | 5 | 12-01-2010 06:28 AM |
| How to implement Web conferencing | Balamohan | Technology & Internet | 5 | 20-12-2009 05:14 AM |
| Want to implement differentiation in C++ | ADEN | Software Development | 1 | 25-10-2008 07:13 PM |