当前位置:网站首页>Return value of unique function of STL
Return value of unique function of STL
2022-04-22 04:42:00 【tonyaqiqi】
unique: Keep only one copy of objects with continuous same values , from s And e Iterator to specify the processing range , And returns the iterator at the end of the compressed sequence
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
const int size = 10;
int a[size] = {
54,10,10,33,33,54,54,36,54,10};
vector <int> v(a, a + size);
vector <int>::iterator start, end, it, pos;
start = v.begin();
end = v.end();
pos = unique(start, end);
cout << *pos;
cout << endl;
for (it = start; it != pos; it++)
cout << *it<<" ";
return 0;
}
Execution results :36
54 10 33 54 36 54 10
unique The return iterator points to 36
36 It's confusing , Isn't it pointing to the end of the sequence ?10 Next
Now print the complete vector, give the result as follows
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
const int size = 10;
int a[size] = {
54,10,10,33,33,54,54,36,54,10};
vector <int> v(a, a + size);
vector <int>::iterator start, end, it, pos;
start = v.begin();
end = v.end();
pos = unique(start, end);
cout << *pos;
cout << endl;
for (it = start; it != end; it++)
cout << *it<<" ";
return 0;
}
36
54 10 33 54 36 54 10 36 54 10
thus it can be seen ,pos It does point to the next... At the end of the sequence ,unique Move non repeating elements to the front , The remaining elements remain in their original positions
版权声明
本文为[tonyaqiqi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220437167287.html
边栏推荐
- 14. Buffferevent timeout event processing
- JVM tuning notes
- Article 1 of linked list
- 2022P气瓶充装考试题库及模拟考试
- [concurrent programming 044] CAS cycle time is too long. What's the problem?
- 2022 Shandong Province safety officer C certificate examination questions and online simulation examination
- Es next related
- 10人小团队创业,如今收入过亿,不融资的简道云是怎么做到的?
- C语言学习记录——삼십칠 字符串函数使用和剖析(1)
- 如何在 Acrobat Pro DC 与其它文件合并创建单个 PDF 文件?
猜你喜欢

2022P气瓶充装考试题库及模拟考试

vue项目 npm run build 打包项目时为css、js文件加时间戳版本号,防止浏览器缓存

Non reentrant information about gethostbyname()

Objectmapper, stop being new like a second product

goland汉化解决方法(下载插件失败的情况下)

安装opencv时遇到的报错

2022G2电站锅炉司炉操作证考试题库及在线模拟考试

2022A特种设备相关管理(电梯)考试题模拟考试题库模拟考试平台操作

SAP export material inventory code

目标检测--轻量级网络(截至2022-04-21)
随机推荐
Linked list Part III
Leetcode refers to offer 18 Delete the node of the linked list
2022 P cylinder filling training questions and answers
[twelfth database operation - stored procedure]
2021-08-14
An article tells you what analysis as a service (AAAS) is
How can devices of different brands be compatible and interconnected? Yiwen teaches you to understand
crypto-js加密算法库【安装教程、缓存加密】
[concurrent programming 044] CAS cycle time is too long. What's the problem?
2022年山东省安全员C证考试题及在线模拟考试
更换vscode解释器
Mapbox creates multiple draggable marker points
Unity的随机数
[untitled]
LeetCode 剑指 Offer 51. 数组中的逆序对***
2022P气瓶充装考试题库及模拟考试
一文告诉你分析即服务(AaaS)到底是什么
论文阅读 (48):A Library of Optimization Algorithms for Organizational Design
Peer interview sharing Lenovo WinForm direction 20220420
Cilcate environment construction