C++算法find_end() 和 find_frist_of()

 

算法

返回值

作用

find_end()

_FwdIt1

搜索某個子序列的最後一次出現地點

find_frist_of()

_FwdIt1

搜索某些元素的首次出現位置

find_end()的參數

_FwdIt1 _First1, _FwdIt1 _Last1,   _FwdIt2 _First2, _FwdIt2 _Last2

find_frist_of()的參數

_FwdIt1 _First1, _FwdIt1 _Last1,   _FwdIt2 _First2, _FwdIt2 _Last2

 

vector<int> createStaticArr()

{

    vector<int> vectorInt;

    vectorInt.push_back(1);

    vectorInt.push_back(2);

    vectorInt.push_back(3);

    vectorInt.push_back(4);

    vectorInt.push_back(5);

    vectorInt.push_back(6);

    vectorInt.push_back(7);

    vectorInt.push_back(8);

    showArr(vectorInt);

    return vectorInt;

}

 

vector<int> createStaticArrTwo()

{

    vector<int> vectorInt;

    vectorInt.push_back(1);

    vectorInt.push_back(2);

    vectorInt.push_back(3);

    vectorInt.push_back(4);

    vectorInt.push_back(5);

    vectorInt.push_back(9);

    vectorInt.push_back(8);

    vectorInt.push_back(7);

    showArr(vectorInt);

    return vectorInt;

}

 

void showArr(vector<int> Arr)

{

    vector<int>::iterator iteArr = Arr.begin();

    for (iteArr ; iteArr != Arr.end(); iteArr++)

    {

         cout << *iteArr << "\t";

    }

    cout << endl;

}

 

void main()

{

    cout << "第一條:"; vector<int> arr1 = createStaticArr();

    cout << "第二條:"; vector<int> arr2 = createStaticArrTwo();

//排序

    sort(arr2.begin(),arr2.end());

    vector<int>::iterator iteLeft;

    iteLeft = find_end(arr1.begin(), arr1.begin()+5, arr2.begin(), arr2.end());

    cout << *iteLeft << endl;

    iteLeft = find_first_of(arr1.begin(), arr1.begin() + 5, arr2.begin(), arr2.end());

    cout << *iteLeft << endl;

}

 

運行結果:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章