InIt find(InIt first, InIt last, const T& val);


ex)

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

using namespace std;

 

void main()

{

     string names[]={"김정수","구홍녀","문병대",

          "김영주","임재임","박미영","박윤자"}

;

     vector<string> as(&names[0],&names[7]);

 

     vector<string>::iterator it;

     it=find(as.begin(),as.end(),"안순자");

     if (it==as.end()) {

          cout << "없다" << endl;

     } else {

          cout << "있다" << endl;

     }

}




InIt find_if(InIt first, InIt last, UniPred F);


ex)

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

using namespace std;

 

bool HasYoung(string who)

{

     return (who.find("영") != string::npos);

}

 

void main()

{

     string names[]={"김정수","구홍녀","문병대",

          "김영주","임재임","박미영","박윤자"};

     vector<string> as(&names[0],&names[7]);

 

     vector<string>::iterator it;

     for (it=as.begin();;it++) {

          it=find_if(it,as.end(),HasYoung);

          if (it==as.end()) break;

          cout << *it << "이(가) 있다." << endl;

     }

}




FwdIt adjacent_find(FwdIt first, FwdIt last [, BinPred F]);

ex)

#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

 

void main()

{

     int ari[]={1,9,3,6,7,5,5,8,1,4};

     vector<int> vi(&ari[0],&ari[9]);

 

     vector<int>::iterator it;

     it=adjacent_find(vi.begin(),vi.end());

     if (it != vi.end()) {

          printf("두 요소가 인접한 값은 %d입니다.\n",*it);

     }

}


FwdIt1 find_first_of(FwdIt1 first1, FwdIt1 last1, FwdIt2 first2, FwdIt2 last2 [, BinPred F]);

ex)

#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

 

void main()

{

     int ar1[]={3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3};

     int ar2[]={2,4,6,8,0};

 

     int *p=find_first_of(&ar1[0],&ar1[25],&ar2[0],&ar2[4]);

     if (p!=&ar1[25]) {

          printf("최초의 짝수는 %d번째의 %d입니다.\n",p-ar1,*p);

     }



'Programing > 자료구조' 카테고리의 다른 글

STL 컨터이네(map,multimap)  (0) 2016.12.01
이중연결리스트 노드 cpp  (0) 2016.12.01
이중연결리스트 노드클래스  (0) 2016.12.01
이중연결리스트.cpp  (0) 2016.12.01
단일연결리스트.cpp  (0) 2016.11.30

+ Recent posts