C++ unique
#include <iostream>
#include <algorithm>
#include <list>
#include <iterator>
#include <functional>
using namespace std;
int main()
{
int source[] = { 1,2,3,3,3,4,5,6,6,7,8,8,8,9,10,3,6,8,12 };
int sourceNum = sizeof(source)/sizeof(source[0]);
list<int> list1;
list<int> list2;
copy(source,source+sourceNum,back_inserter(list1));
copy(source,source+sourceNum,back_inserter(list2));
list<int>::iterator list_iter1;
for (list_iter1 = list1.begin();list_iter1 != list1.end(); ++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
list<int>::iterator list_iter2;
list_iter2 = unique(list1.begin(),list1.end());
for (list_iter1 = list1.begin();list_iter1 != list_iter2; ++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
list<int>::iterator list_iter3 = unique(list2.begin(),list2.end(),greater<int>());
for (list_iter1 = list2.begin(); list_iter1 != list_iter3; ++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
system("pause");
return 0;
}
================================================
1 2 3 3 3 4 5 6 6 7 8 8 8 9 10 3 6 8 12
----------------------------------------------
1 2 3 4 5 6 7 8 9 10 3 6 8 12
----------------------------------------------
1 2 3 3 3 4 5 6 6 7 8 8 8 9 10 12
----------------------------------------------
请按任意键继续. . .
C++ unique的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] Unique Paths 不同的路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 2 Unique Binary Search Trees II_Leetcode
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- Constraint5:unique 约束和null
unique约束使用unique index来限制列值的唯一性: 创建unique约束之后,column中允许插入null值,unique 约束将两个null值看作是相同的(即null=null为tr ...
随机推荐
- 【转】Linux编译链接问题----静态库和动态库
Linux静态库和动态库的命名规则 静态函数库 静态库的名字一般是libxxx.a,利用静态库编译生成的文件比较大,因为整个静态库所有的数据都会被整合进目标代码中. a) 优点: 编译后,可执行文件不 ...
- Go语言——值方法 & 指针方法
1 package main import ( "fmt" "sort" ) type SortableStrings []string type Sortab ...
- keil 选项卡设置
*1.optimization : level2. *2. 2)硬件目标设置选项卡(Target),见图6所示. 图6 1:选择硬件目标设置选项卡 2:指定用于的晶振频率 3:在应用中可以选择实时操 ...
- HRNet网络结构
最近正在阅读CVPR2019的论文Deep High-Resolution Representation Learning for Human Pose Estimation. 无奈看论文中的Netw ...
- Mysql读写分离 及高可用高性能负载均衡实现
什么是读写分离,说白了就是mysql服务器读的操作和写的操作是分开的,当然这个需要两台服务器,master负责写,slave负责读,当然我们可以使用多个slave,这样我们也实现了简单意义上的高可用和 ...
- Vant UI 组件库如何做rem适配?
Vant是一款移动端基于vue的组件库,V2.1.1版本非常棒.文档地址:https://youzan.github.io/vant/?source=vuejsorg#/zh-CN/intro,那么V ...
- 机器学习中的数学-强大的矩阵奇异值分解(SVD)及其应用
版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...
- PWA
附一个示例e6书写 todolist的示例,切换list的状态: //todolist示例 const toggleTodo = (id)=>{ setTodos(todos => tod ...
- webpack4 Cannot find module '@babel/core'
Error: // webpackCannot find module '@babel/core'解决办法一: 原因"babel-loader": "^8.0.0&quo ...
- rabbitmq可靠性
本文翻译汇总自rabbitmq的官方文档. 翻译使用谷歌翻译后简单修改,部分内容读起来仍然比较晦涩,不过意思传达到了. 可靠性指南 本页介绍了如何使用AMQP和RabbitMQ的各种功能来实现可靠 ...