unique &unique_copy
unique (ForwardIterator first, ForwardIterator last);
unique (ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
类属性算法unique的作用是从输入序列中“删除”所有相邻的重复元素。该算法删除相邻的重复元素(不相邻的元素无法删除),
然后重新排列输入范围内的元素(没有进行排序,按照原序列排列),并且返回一个迭代器(容器的长度没变,只是元素顺序
改变了),表示无重复的值范围得结束。
unique_copy (InputIterator first, InputIterator last,OutputIterator result);
unique_copy (InputIterator first, InputIterator last,OutputIterator result, BinaryPredicate pred);
unique_copy 唯一的区别在于:unique_copy 接受第三个迭代器实参,用于指定复制不重复元素的目标序列。
ex:
// unique algorithm example
#include <iostream>
#include <algorithm>
#include <vector>
bool myfunction (int i, int j) {
return (i==j);
}
int main () {
int myints[] = {10,20,20,20,30,30,20,20,10}; // 10 20 20 20 30 30 20 20 10
std::vector<int> myvector (myints,myints+9);
// using default comparison:
std::vector<int>::iterator it;
it = std::unique (myvector.begin(), myvector.end()); // 10 20 30 20 10 ? ? ? ?
// ^
myvector.resize( std::distance(myvector.begin(),it) ); // 10 20 30 20 10
// using predicate comparison:
std::unique (myvector.begin(), myvector.end(), myfunction); // (no changes)
// print out content:
std::cout << "myvector contains:";
for (it=myvector.begin(); it!=myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
unique &unique_copy的更多相关文章
- c++ STL unique , unique_copy函数
一.unique函数 类属性算法unique的作用是从输入序列中"删除"全部相邻的反复元素. 该算法删除相邻的反复元素.然后又一次排列输入范围内的元素,而且返回一个迭代器(容器的长 ...
- 数据离散化 ( 以及 stl 中的 unique( ) 的用法 )+ bzoj3289:Mato的文件管理
http://blog.csdn.net/gokou_ruri/article/details/7723378 ↑惯例Mark大神的博客 bzoj3289:Mato的文件管理 线段树求逆序对+莫队 ...
- STL--STL和她的小伙伴们:
STL--概述: 标准模板库(StandardTemplateLibrary,STL),是C++程序设计语言标准模板库.STL是由Alexander Stepanov.Meng Lee和David R ...
- C++ 容器一些细节
今天学习是看到了讲解C++容器的一些细节用法,故记之!参考:http://www.cnblogs.com/answeryi/archive/2011/12/16/2289811.html: 目录 == ...
- STL函数模板(即算法)一览
查找算法 adjacent_find:找出一个串中第一个不符合次序的地方 find,find_if:找出第一个符合条件的元素 find_first_of:在一个串中寻找第一个与另一个串中任意一个元素相 ...
- C++ 容器及选用总结
目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...
- ACM学习
转:ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. US ...
- ACM竞赛常用STL(二)之STL--algorithm
<algorithm>无疑是STL 中最大的一个头文件,它是由一大堆模板函数组成的.下面列举出<algorithm>中的模板函数: adjacent_find / binary ...
- c++容器使用总结(转载)
目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...
随机推荐
- ios NSKeyedArchiver 保存对象与对象数组
废话不说,直接上代码 // // CommunityTool.h // SmartCommunity // // Created by chenhuan on 15/9/2. // Copyright ...
- 3月20日html(二) 图片热点,网页划分,表单
1.图片热点: 规划出图片上的一个区域,可以做出超链接,直接点击图片区域就可以完成跳转的效果. <img src=" usemap="map" name=" ...
- 原生app,WEBAPP,混合app
什么叫做原生App? 原生App是专门针对某一类移动设备而生的,它们都是被直接安装到设备里,而用户一般也是通过网络商店或者卖场来获取例如 The App Store 与 Android Ap ...
- Java学习笔记--HashMap中使用object做key的问题【转】
在HashMap中,如果需要使用多个属性组合作为key,可以将这几个属性组合成一个对象作为key.但是存在的问题是,要做get时,往往没办法保存当初put操作时的key object的referenc ...
- Caffe--solver.prototxt配置文件 参数设置及含义
####参数设置################### 1. ####训练样本### 总共:121368个batch_szie:256将所有样本处理完一次(称为一代,即epoch)需要:121368/ ...
- 使用Volley StringRequest Get的方式进行发票查询操作
//进行发票查询 btnFpSelect.setOnClickListener(btnFpSelectClickListener); private OnClickListener btnFpSele ...
- PowerShell正则表达式(一) 定义模式
PowerShell正则表达式(一) 定义模式 7 29 9月, 2013 在 Powershell tagged 正则表达式 by Mooser Lee 本文索引 [隐藏] 1限定符 2识别IP地 ...
- bzoj3629[JLOI2014]聪明的燕姿
http://www.lydsy.com/JudgeOnline/problem.php?id=3629 搜索. 我们知道: 如果$N=\prod\limits_{i=1}^{m}p_{i}^{k_{ ...
- FreeBSD ipfw App配置Examples
Step # 1: Enabling IPFW Open /etc/rc.conf file # vi /etc/rc.conf Append following settings: firewall ...
- 法爱格2014 春夏新款欧美纯色修身高腰无袖吊带V领 拼接性感 连衣裙 黑色 M【图片 价格 品牌 报价】-京东
法爱格2014 春夏新款欧美纯色修身高腰无袖吊带V领 拼接性感 连衣裙 黑色 M[图片 价格 品牌 报价]-京东 法爱格2014 春夏新款欧美纯色修身高腰无袖吊带V领 拼接性感 连衣裙 黑色 M