青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

stl中的algorithms真是強(qiáng)!我能想到的算法都有啊!

對容器中的元素:排序,查找,替換,分段,求和 。。。。。。。swap  ratate  sort  search   merge  range copy 。。。。。。。。。太多拉,說不完啊,希望那位有所有函數(shù)的列表啊,給一個(gè)吧,找的時(shí)候好找啊!看看下面的有沒有見過啊!

#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

 

int main()

{

    copy (istream_iterator<string>(cin),         // beginning of source

          istream_iterator<string>(),            // end of source

          ostream_iterator<string>(cout,"\n"));  // destination

}

 

#include <cstdlib>

#include "algostuff.hpp"

using namespace std;

 

class MyRandom {

  public:

    ptrdiff_t operator() (ptrdiff_t max) {

        double tmp;

        tmp = static_cast<double>(rand())

                / static_cast<double>(RAND_MAX);

        return static_cast<ptrdiff_t>(tmp * max);

    }

};

 

int main()

{

    vector<int> coll;

 

    INSERT_ELEMENTS(coll,1,20);

    PRINT_ELEMENTS(coll,"coll:     ");

 

    // shuffle all elements randomly

    random_shuffle (coll.begin(), coll.end());

 

    PRINT_ELEMENTS(coll,"shuffled: ");

 

    // sort them again

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

    PRINT_ELEMENTS(coll,"sorted:   ");

 

    /* shuffle elements with self-written random number generator

     * - to pass an lvalue we have to use a temporary object

     */

    MyRandom rd;

    random_shuffle (coll.begin(), coll.end(),    // range

                    rd);                 // random number generator

 

    PRINT_ELEMENTS(coll,"shuffled: ");

}

 

#include "algostuff.hpp"

using namespace std;

 

// checks whether an element is even or odd

bool checkEven (int elem, bool even)

{

    if (even) {

        return elem % 2 == 0;

    }

    else {

        return elem % 2 == 1;

    }

}

 

int main()

{

    vector<int> coll;

 

    INSERT_ELEMENTS(coll,1,9);

    PRINT_ELEMENTS(coll,"coll: ");

 

    /* arguments for checkEven()

     * - check for: ``even odd even''

     */

    bool checkEvenArgs[3] = { true, false, true };

 

    // search first subrange in coll

    vector<int>::iterator pos;

    pos = search (coll.begin(), coll.end(),       // range

                  checkEvenArgs, checkEvenArgs+3, // subrange values

                  checkEven);                     // subrange criterion

 

    // loop while subrange found

    while (pos != coll.end()) {

        // print position of first element

        cout << "subrange found starting with element "

             << distance(coll.begin(),pos) + 1

             << endl;

 

        // search next subrange in coll

        pos = search (++pos, coll.end(),              // range

                      checkEvenArgs, checkEvenArgs+3, // subr. values

                      checkEven);                     // subr. criterion

    }

}

 

#include "algostuff.hpp"

using namespace std;

 

int main()

{

    int c1[] = { 1, 2, 2, 4, 6, 7, 7, 9 };

    int num1 = sizeof(c1) / sizeof(int);

 

    int c2[] = { 2, 2, 2, 3, 6, 6, 8, 9 };

    int num2 = sizeof(c2) / sizeof(int);

 

    // print source ranges

    cout << "c1:                         " ;

    copy (c1, c1+num1,

          ostream_iterator<int>(cout," "));

    cout << endl;

    cout << "c2:                         " ;

    copy (c2, c2+num2,

          ostream_iterator<int>(cout," "));

    cout << '\n' << endl;

 

    // sum the ranges by using merge()

    cout << "merge():                    ";

    merge (c1, c1+num1,

           c2, c2+num2,

           ostream_iterator<int>(cout," "));

    cout << endl;

 

    // unite the ranges by using set_union()

    cout << "set_union():                ";

    set_union (c1, c1+num1,

               c2, c2+num2,

               ostream_iterator<int>(cout," "));

    cout << endl;

 

    // intersect the ranges by using set_intersection()

    cout << "set_intersection():         ";

    set_intersection (c1, c1+num1,

                      c2, c2+num2,

                      ostream_iterator<int>(cout," "));

    cout << endl;

 

    // determine elements of first range without elements of second range

    // by using set_difference()

    cout << "set_difference():           ";

    set_difference (c1, c1+num1,

                    c2, c2+num2,

                    ostream_iterator<int>(cout," "));

    cout << endl;

 

    // determine difference the ranges with set_symmetric_difference()

    cout << "set_symmetric_difference(): ";

    set_symmetric_difference (c1, c1+num1,

                              c2, c2+num2,

                              ostream_iterator<int>(cout," "));

    cout << endl;

}
--------------------------------------------------------
一個(gè)簡單的函數(shù)列表:希望給大家查找?guī)矸奖悖碜裕?A >http://www.csci.csusb.edu/dick/samples/stl.algorithms.html

Glossary for the C++ Standard Library

  1. binary_function::=A function that has two arguments f(x,y).
  2. binary_predicate::=a function or function_object that returns a bool value when given two items, used for testing to see if items match, or that they are in order.
  3. function::=Something f that can be called like this f(x) for an argument x.
  4. function_object::=any instance of a class that has defined and operator() and so can be called as if it was a function.
  5. interval::=a range.
  6. iterator::=an object that indicates an item in a container,
  7. iterators::=plutral of iterator.
  8. predicate::=a function or function_object that returns a bool value when given an item.
  9. range::= a sequence of items in a container given by a pair of iterators indicating the beginning and the point after the last one.

    Search


    (find): looks for a value in a range.
    (find_if): looks for items in a range that satisfy a predicate.
    (find_first_of): looks for items in first range that is also in the second range or uses a binary_predicate to find first matching item.
    (find_end): looks backward for items in first range that are not also in the second range or uses a binary_predicate to find first non_matching item.
    (adjacent_find): looks for first pair in range that are equal, or match under a binary_predicate.


    (max): returns larger of two items, possible using a binary_predicate.
    (max_element): finds largest item in a range, may use a binary_predicate. [ timeSelectionSort.cpp ]
    (min): returns larger of two items, possible using a binary_predicate.
    (min_element): finds largest item in a range, may use a binary_predicate.


    (mismatch): search two parallel ranges and returns position of the first one that is unequal or doesn't satisfy a binary_predicate.


    (search): look in first range for an occurrence of the second range, possibly using a binary_predicate.
    (search_n): look in range for an occurrence of n items equal to a value, possibly using a binary_predicate.

    Scan, compare, and count


    (count): scan range and count occurrence of a value.
    (count_if): scan range and count times a predicate is true.
    (equal): test if a range equals, element another parallel range, possibly using a binary_predicate.
    (for_each): Apply a function to every item in a range.

    Copy, Move and swap


    (copy): Copy items in range to another place indicate by its start. There is a surprising way to read and write data to/from an input/output stream by using copy and adapters that give iterators accessing a stream. For example, suppose we have a range [begin, end) ints and want to output them separated by tabs we can write:

     		copy(begin, end, ostream_iterator<int> (cout, "\t") );
    To read ints into a vector v we would write
     		copy(istream_iterator<int>(cin), istream_iterator<int>(), back_inserter(v));


    (copy_backward): Copy items in range to another place indicated by its end.


    (swap): swaps values of two given variables.
    (iter_swap): swaps two items in a container indicated by iterators. Used in [ timeSelectionSort.cpp ] [ timeQuickSort.cpp ]


    (swap_ranges): interchanges value between two ranges.
    (reverse): places the elements in the reverse order.
    (reverse_copy): creates a backwards copy of a range.
    (rotate): given a middle point in a range, reorganizes range so that middle comes first...
    (rotate_copy): creates a rotated copy.


    (partition): takes a range and reorganizes the items so that a predicate is true at first and then false... A key part of QuickSort! [ timeQuickSort.cpp ]
    (stable_partition): takes a range and reorganizes the items so that a predicate is true at first and then false... but in each part the items are still in the same sequence (with some gaps).


    (random_shuffle): shuffles a range, you can supply your own random number generator.

    Change and Delete


    (replace): scan a range and replace given old values by given new value.
    (replace_if): scan a range and replace given old values by given new value IF a predicate is true.
    (replace_copy): make a copy of a range but replace given old values by given new value.
    (replace_copy_if): make a copy of a range but replace given old values by given new value IF a predicate is true.
    (remove): deletes items in a range that equal a given value.
    (remove_if): deletes items in a range if a predicate is true.
    (remove_copy): makes a copy of items in a range but not those with a given value.
    (remove_if): makes a copy of items in a range but not those where a predicate is true.


    (unique): deletes duplicated items, leaves the first. Can use a binary_predicate.
    (unique_copy): copies range but not duplicated items, leaves the first. Can use a binary_predicate.

    Generate and Fill


    (fill): change a range to all have the same given value.
    (fill_n): change n items to all have the same given value.
    (generate): change items in a range to be values produced by a function_object.
    (generate_n): change n items to be values produced by function_object.
    (transform): scans a range and for each use a function to generate a new object put in a second container, OR takes two intervals and applies a binary operation to items to generate a new container.

    Sort


    (sort): reorganize a range to be in order, can use a binary_predicate. For example: [ timeVectorSort.cpp ]

    Also some containers have a sort member function: [ timeListSort.cpp ]


    (stable_sort): like sort but equivalent items are kept in the same sequence.
    (partial_sort): Sorts part of a range.
    (partial_sort_copy): makes a copy of a range but with part sorted.


    (nth_element): Sorts out just the nth element!

    Search, Merge and Permute Sorted Containers


    (binary_search): search a sorted range for a value.
    (lower_bound): finds first place in a sorted range which is not less than a given value.
    (upper_bound): finds first place in a sorted range which is not greater than a given value.
    (equal_range): finds a range that brackets a given value.


    (merge): Combines two sorted ranges to give a new sorted range both all their items.
    (inplace_merge): Combines two sorted halves of a range to give a sorted range both all their items. [ timeMergeSort.cpp ]


    (next_permutation): permutes items in a range... will generate each possible order once until it returns false.
    (prev_permutation): undoes next_permutation

    Set Operations: union, intersection, complement,...

    [ timeMultisetSort.cpp ]


    (includes): set theoretic test.
    (set_union ): set theoretic operation.
    (set_intersection): set theoretic operation.
    (set_difference): set theoretic operation.
    (set_symmetric_difference): set theoretic operation.

    Numeric algorithms


    (accumulate): adds up items in range starting with given initial value, can also do any binary operation if it is given as an function of two arguments(binary_function).Used to code the math \Sigma and \Pi symbols.
    (inner_product): the heart of linear algebra, but can be generalized to do other things by supplying two binary_function s.
    (partial_sum): scans range and replaces items by sum so far, can use general binary_function.
    (adjacent_difference): Scans range and replace items by differences

    Heaps

    The big lumps rise to the top. Seriously! A heap is an array of vector where the first item is always the biggest tiem. Further, the next two smallest items are in the second and third places. After the second you have the fourth and fithf, and after the third the sixth and seventh. As a rule the n'th item is larger than the 2*n'th and (2*n+1)'th items. For more take CSCI330 Data Structures.


    (make_heap): rearranges a range so that it becomes a heap.
    (sort_heap): takes a heap and creates a sorted container from it (by popping items).

    Combining make_heap and sort_heap gives a pretty good [O(n log n)] sort: [ timeHeapSort.cpp ]


    (push_heap): puts a new element into a heap and rearranges it to still be a heap.
    (pop_heap): removes the top/largest element and rearranges to leave a heap behind.

    Examples of use

    [ http://www.csci.csusb.edu/dick/examples/ ]

posted on 2005-12-16 17:01 夢在天涯 閱讀(3593) 評論(5)  編輯 收藏 引用 所屬分類: STL/Boost

評論

# re: stl中的algorithms真是強(qiáng)!我能想到的算法都有啊! 2005-12-17 01:21 redbox

速度有點(diǎn)慢  回復(fù)  更多評論   

# re: stl中的algorithms真是強(qiáng)!我能想到的算法都有啊! 2005-12-19 08:53 夢在天涯

妳是說stl中的算法的速度慢嗎?

但是對于一般的問題我覺的都可以滿足的吧!

^_^!~~·  回復(fù)  更多評論   

# re: stl中的algorithms真是強(qiáng)!我能想到的算法都有啊! 2008-03-27 18:36 匿名

提示錯(cuò)誤 can't find "algostuff.hpp",請問是怎么回事啊?  回復(fù)  更多評論   

# re: stl中的algorithms真是強(qiáng)!我能想到的算法都有啊! 2008-07-28 11:38 21

不知道就別難說,誰說慢了
  回復(fù)  更多評論   

# re: stl中的algorithms真是強(qiáng)!我能想到的算法都有啊! 2008-12-13 12:12 zmm

通過在MSDN中查找其中一個(gè)函數(shù)(比如find),然后點(diǎn)擊與目錄同步也可以看到algorithm庫中的所以算法。  回復(fù)  更多評論   

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1812163
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              亚洲成人自拍视频| 亚洲乱码国产乱码精品精可以看| 亚洲二区视频| 亚洲日本va在线观看| 亚洲二区在线视频| 99热这里只有精品8| 亚洲永久免费精品| 久久精品国产99| 美女精品自拍一二三四| 亚洲第一综合天堂另类专| 亚洲国产一区二区三区在线播| 亚洲精品一区二区三区樱花| 香蕉久久精品日日躁夜夜躁| 久热精品视频| 国产精品一区二区在线观看网站| 国产在线一区二区三区四区| 最新热久久免费视频| 正在播放亚洲| 久久亚洲精品视频| 在线视频免费在线观看一区二区| 欧美中在线观看| 欧美高清在线观看| 国内成+人亚洲+欧美+综合在线| 亚洲狼人综合| 久久乐国产精品| 一本色道久久88综合亚洲精品ⅰ| 欧美一区二视频在线免费观看| 欧美激情视频在线免费观看 欧美视频免费一| 欧美深夜影院| 亚洲国产精品尤物yw在线观看| 亚洲免费网站| 亚洲精品影视| 美女黄毛**国产精品啪啪| 性欧美8khd高清极品| 国产精品毛片大码女人| 亚洲第一级黄色片| 小处雏高清一区二区三区| 欧美激情精品久久久久久久变态| 亚洲一区三区电影在线观看| 欧美国产日韩一区二区| 韩国av一区| 久久国产主播| 亚洲综合首页| 国产精品欧美久久久久无广告| 亚洲精品一区在线观看| 欧美成人一区二区三区| 久久成人国产| 国产一区二区三区电影在线观看| 午夜精品久久久久久99热| 亚洲美女精品久久| 欧美日韩国产成人在线91| 亚洲毛片在线免费观看| 欧美成人综合在线| 蜜桃av一区二区三区| 亚洲国产合集| 欧美黄色日本| 欧美精品色一区二区三区| 日韩一二三在线视频播| 亚洲国产综合91精品麻豆| 免费国产一区二区| 亚洲欧洲精品一区二区三区波多野1战4| 久久久999精品视频| 欧美一级播放| 依依成人综合视频| 欧美激情精品久久久六区热门 | 亚洲在线观看免费| 亚洲天堂av电影| 国产精品永久免费观看| 欧美专区18| 久久国内精品视频| 91久久嫩草影院一区二区| 亚洲国产欧美国产综合一区| 亚洲欧美日韩国产成人| 亚洲欧美在线免费| 国内外成人免费激情在线视频| 欧美专区中文字幕| 久久久www| 一本久久a久久精品亚洲| 日韩视频不卡| 国产人成精品一区二区三| 老司机67194精品线观看| 免费欧美网站| 午夜精品在线看| 久久久久久午夜| 99国产精品99久久久久久| 亚洲免费高清视频| 国产农村妇女毛片精品久久莱园子| 久久婷婷av| 欧美日韩在线播放| 99av国产精品欲麻豆| 欧美大片在线影院| 亚洲欧美日韩一区在线观看| 久久免费视频在线| 亚洲性感激情| 美女国产精品| 久久er精品视频| 欧美久久久久久久| 久久亚洲影院| 国产精品日韩精品欧美精品| 欧美国产精品日韩| 国产目拍亚洲精品99久久精品| 欧美国产精品一区| 国产日韩欧美二区| 一区二区三区毛片| 99精品免费网| 久久免费少妇高潮久久精品99| 亚洲一区二区在线免费观看视频| 久久女同精品一区二区| 午夜精品福利电影| 免费成年人欧美视频| 久久久精品一区二区三区| 欧美日韩一区在线观看视频| 久久婷婷国产麻豆91天堂| 国产精品色网| 一本色道久久88综合亚洲精品ⅰ | 亚洲一区在线观看视频| 欧美成人69| 亚洲第一在线视频| 亚洲国产成人在线视频| 久久精品中文字幕一区| 久久精品免费播放| 国产精品呻吟| 国产精品99久久久久久久vr| 日韩午夜三级在线| 欧美成人午夜激情| 欧美激情一区二区三区高清视频| 黄色成人精品网站| 久久精品成人一区二区三区| 欧美在线欧美在线| 国产精品一区视频网站| 亚洲欧美一区二区三区极速播放| 亚洲影院在线| 国产美女诱惑一区二区| 销魂美女一区二区三区视频在线| 欧美一级专区| 国产日韩成人精品| 亚洲欧美日韩在线一区| 久久不射中文字幕| 国产视频一区在线观看一区免费| 亚洲欧美在线观看| 久久夜色精品国产| 亚洲国产91| 欧美伦理一区二区| 日韩一区二区高清| 欧美一进一出视频| 狠狠色狠狠色综合日日小说| 久久频这里精品99香蕉| 亚洲欧洲日本mm| 亚洲一区二区不卡免费| 欧美美女操人视频| 亚洲欧美日韩天堂一区二区| 久久久蜜桃精品| 最新成人av网站| 欧美日韩一区二区三区免费| 一区二区日韩伦理片| 久久久精品性| 亚洲电影在线播放| 亚洲午夜激情免费视频| 国产日韩在线一区二区三区| 久久乐国产精品| 99这里只有久久精品视频| 欧美一区二区三区免费视| 国自产拍偷拍福利精品免费一| 女生裸体视频一区二区三区| 一本色道久久综合狠狠躁篇怎么玩 | 国产亚洲欧美一区二区| 日韩一级欧洲| 久久女同互慰一区二区三区| 亚洲国内自拍| 国产精品久久久| 久久久噜噜噜久久中文字幕色伊伊| 亚洲国产精品va在线看黑人动漫 | 91久久在线观看| 国产精品区二区三区日本| 噜噜噜91成人网| 亚洲夜晚福利在线观看| 欧美韩日一区二区三区| 欧美一级专区| 中文亚洲视频在线| 亚洲第一精品夜夜躁人人爽| 国产精品99免费看| 欧美成人一区二免费视频软件| 亚洲你懂的在线视频| 亚洲欧洲午夜| 嫩模写真一区二区三区三州| 亚洲欧美在线一区| 亚洲精品久久久久久久久久久 | 在线国产日韩| 国产精品久久久久99| 免费欧美在线| 久久久精彩视频| 午夜精品久久久久久久久久久久久 | 在线观看视频免费一区二区三区| 欧美电影免费观看大全| 欧美一区二区三区免费在线看| 亚洲欧洲日本在线| 亚洲第一页中文字幕| 欧美成人免费在线| 另类亚洲自拍| 久久久久综合|