Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Help me to implement adjacent_find() in C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-02-2010
Member
 
Join Date: Jan 2010
Posts: 22
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.
Reply With Quote
  #2  
Old 10-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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.
Reply With Quote
  #3  
Old 10-02-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
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;
   }
Output :
Code:
  3 3 2 2
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 10-02-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
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;
   }
}
Reply With Quote
  #5  
Old 10-02-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
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 );
Reply With Quote
  #6  
Old 10-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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;
   }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 03:51 AM.