Find the first subsequence

Started by aruljothi, Jun 11, 2009, 07:17 PM

Previous topic - Next topic

aruljothi

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv)
{
  int elems[] = {5, 6, 9, 8, 8, 3};

  vector<int> myVector(elems, elems + 6);
  vector<int>::const_iterator it, it2; 

  // Find the first subsequence
  int sub[] = {8, 3};
  it = search(myVector.begin(), myVector.end(), sub, sub + 2);
  if (it != myVector.end()) {
    cout << "Found subsequence 8, 3 at position " << it - myVector.begin()
   << endl;
  }

  return (0);
}