STL 算法

STL算法分类
*非修改式序列操作   (ep:find() for_each())
*修改式序列操作     (ep:transform() random_shuffle() copy())
*排序和相关操作     (ep:sort())
(以上被包含在 #include <algorithm>)

*通用数字运算     
(以上被包含在 #include <numeric>)

 

复制版本 函数名后面加 _copy     将函数应用与容器加  _if    ep:replace_copy_if()

 

 

 

 

 


////////////////////////////////////////////////////////////
//
//strgst.cpp    STL与string 使用排列组合
//
////////////////////////////////////////////////////////////
// strgstl.cpp -- applying the STL to a string
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    using namespace std;
    string letters;
   
    cout << "Enter the letter grouping (quit to quit): ";
    while (cin >> letters && letters != "quit")
    {
        cout << "Permutations of " << letters << endl;
        sort(letters.begin(), letters.end());
        cout << letters << endl;
        while (next_permutation(letters.begin(), letters.end())) //next_permutation()排列组合无则返false
            cout << letters << endl;
        cout << "Enter next sequence (quit to quit): ";
    }
    cout << "Done.\n";
   
    return 0;
}

posted @ 2007-03-18 18:58  Edward Xie  阅读(206)  评论(0)    收藏  举报