unique函数自我理解
来源:互联网 发布:yandex优化怎么做 编辑:程序博客网 时间:2024/06/09 18:59
unique()函数是STL里面一个非常有用的去重的函数,首先,它的功能是去除相邻的重复的元素,只保留其中一个,但是有一点一定得注意:它并没有真正的去除,而只是,除了保留一个外,其余的重复的元素均被它搞到容器后面去了,该函数的返回值是需要删除的重复值的第一个元素的地址.
例如:一个vector<int>a={1,2,3,3,3,4},unique(a.begin(),a.end()),它的返回值是{1 ,2, 3, 4,3 ,3}这个排列中4后面的3的位置。所以,要想真正的删除此重复的元素,还得借助于erase()函数。
a.erase(unique(a.begin(),a.end()),a.end());
最后呢,因为有时候给定的序列不是有序的,因此还需要在执行unique()前进行sort().
0 0
- unique函数自我理解
- 多态,虚函数的一些自我理解
- php 两个数组函数自我理解
- 自我理解
- unique函数
- unique函数
- unique函数
- unique 函数
- unique函数
- unique函数
- unique函数
- unique函数
- unique函数
- unique函数
- 【unique函数】
- 官方aidl 自我理解
- Nsis的自我理解
- AR自我理解
- AOJ.864 函数
- 远程SSH连接服务与基本排错
- Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied b
- 第八 LDAP 网络用户帐号
- 动态库的使用
- unique函数自我理解
- 表单校验
- Matlab R2014b配置vlfeat0.9.20
- 张正友标定法
- linux命令之uname
- opencv:HSV颜色模型
- 【Intellij IDEA】eclipse项目导入
- Unity切换场景淡入淡出效果
- 厉害了我的哥