第十一章 泛型算法 C++ PRIMER

vector<int>::const_iterator result = find(vector.begin(). vector.end(),search_value); 如果查找失败,分会end()  如果有两个,会返回哪一个的迭代器?

int *reauslt = find(ia,ia+6,search_value); 也可以同样处理字符串

算法要以<algorithm><numeric>,依赖于迭代器和迭代器的算法实现,算法可能改变值,可能移动元素,单从不直接添加或者删除元素

int sum = accumulate(vec.begin(),vec.end(),42); 最后一个参数是必须的,因为accumulate并不知道叠加的类型     在程序中直接写一个“12345”,系统认为string 还是 char*, 是不是const ?

fill(vec.begin().vec.end(),0); 在指定范围内插入第三个参数

unique函数也不改变迭代器的大小,只是将重复的放到了后面

vector<string>::iterator end_unique = unique(words.begin(),words.end());

words.erase(end_unique,words.end()); ////这个erase还是要好好看看的

stable_sort(words.begin(),words.end(),isshorter);

swap();的用法,我还没有找到,应该好好找找

后面高级点的迭代器没有看,第一遍,千万不要太贪

posted on 2014-05-18 14:32  berkeleysong  阅读(132)  评论(0编辑  收藏  举报

导航