STL(from:http://www.cnblogs.com/henryzc/articles/298882.html)

转载 2007年09月23日 14:52:00
对容器中的元素:排序,查找,替换,分段,求和 。。。。。。。swap  ratate  sort  search   merge  range copy 。。。。。。。。。太多拉,说不完啊,希望那位有所有函数的列表啊,给一个吧,找的时候好找啊!看看下面的有没有见过啊!

#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;

}
--------------------------------------------------------
一个简单的函数列表:希望给大家查找带来方便!来自:
http://www.csci.csusb.edu/dick/samples/stl.algorithms.html
 
Glossary for the C++ Standard Library

binary_function::=A function that has two arguments f(x,y).
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.
function::=Something f that can be called like this f(x) for an argument x.
function_object::=any instance of a class that has defined and operator() and so can be called as if it was a function.
iterator::=an object that indicates an item in a container,
iterators::=plutral of iterator.
predicate::=a function or function_object that returns a bool value when given an item.
range::= a sequence of items in a container given by a pair of iterators indicating the beginning and the point after the last one.

(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.
 

(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): 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.

(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.
 

(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): 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!

(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

(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.

(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
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. [
http://www.csci.csusb.edu/dick/examples/ ]
Examples of use
Heaps
Numeric algorithms
Set Operations: union, intersection, complement,...
Search, Merge and Permute Sorted Containers
Sort
Generate and Fill
Change and Delete
Copy, Move and swap
Scan, compare, and count
Search

给COM/ActiveX控件签名(signcode,cab,pfx,pvk)

 【虎.无名】准备用到一个web页面口令保护的小控件,但是发行商自己没有购买商用的数字证书,而是使用自己用openssl生成的私有证书来签名的。公司以前倒是申请过一个用于网站的ssl证书,但不知道能否...
  • suifeng0117
  • suifeng0117
  • 2010年05月16日 11:19
  • 6148

http://www.cnblogs.com/freeliver54/p/3725979.html

写在前面 服务号和订阅号 URL配置 创建菜单 查询、删除菜单 接受消息 发送消息(图文、菜单事件响应) 示例Demo下载 后记   最近公司在做微信开发,其实就是接口开发,网上找了很多资料,当然...
  • huningjun
  • huningjun
  • 2016年12月12日 11:50
  • 2339

PCL点云库配置整理

配置PCL花了好长一段时间,在这里整理一些看过的文章,链接
  • yangliuqing19
  • yangliuqing19
  • 2016年01月21日 14:33
  • 602

C++:STL标准入门汇总(http://www.cnblogs.com/shiyangxt/archive/2008/09/11/1289493.html)

第一部分:(参考百度百科)  一、STL简介 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称。它是由Alexander Step...
  • kobewncs
  • kobewncs
  • 2015年03月30日 20:56
  • 268

http://www.cnblogs.com/hitwtx/articles/2468633.html

JSON net.sf.json(JSON转换)
  • baidu_35931316
  • baidu_35931316
  • 2016年12月20日 16:39
  • 313

http://www.cnblogs.com/onlys/articles/jQuery.html

jQuery选择器总结   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2...
  • a913702626
  • a913702626
  • 2014年09月19日 10:34
  • 250

http://www.cnblogs.com/king-77024128/articles/2666230.html

#sudo apt-get install nfs-kernel-server ubuntu12.04中的已经是最新版本了,无需安装 打开/etc/exports文件,在末尾加入: ...
  • bys2000000
  • bys2000000
  • 2015年09月17日 18:25
  • 169

http://www.cnblogs.com/dudu/articles/4449.html

Attribute在.net编程中的应用(一) Attribute的基本概念 经常有朋友问,Attribute是什么?它有什么用?好像没有这个东东程序也能运行。实际上在.Net中,Attrib...
  • kendyhj9999
  • kendyhj9999
  • 2013年12月04日 14:52
  • 833

http://www.cnblogs.com/kristain/articles/2033566.html

public static void main(String[] args) {   Map map = new HashMap();   map.put("1", "value1");  ...
  • qq_31975437
  • qq_31975437
  • 2016年05月10日 21:18
  • 366

http://www.cnblogs.com/devilmsg/articles/1266336.html

lib和dll文件的区别和联系 什么是lib文件,lib和dll的关系如何 (2008-04-18 19:44:37)     (1)lib是编译时需要的,dll是运行时需要的。  如果要完...
  • kakaxi2222
  • kakaxi2222
  • 2014年10月14日 23:54
  • 295
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:STL(from:http://www.cnblogs.com/henryzc/articles/298882.html)
举报原因:
原因补充:

(最多只允许输入30个字)