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 ...
随机推荐
- 好用的redis客户端和Mongo客户端推荐
Another Redis resktop manager electron页面 github地址 MongoCompass 社区版 下载地址
- 网络分类及OSI七层模型
一.网络分类: 局域网(LAN)是指在某一区域内由多台计算机互联成的计算机组.一般是方圆几千米以内.局域网可以实现文件管理.应用软件共享.打印机共享.工作组内的日程安排.电子邮件和传真通信服务等功能. ...
- 7.MapReduce操作Hbase
7 HBase的MapReduce HBase中Table和Region的关系,有些类似HDFS中File和Block的关系.由于HBase提供了配套的与MapReduce进行交互的API如 Ta ...
- idou老师教你学Istio 18 : 如何用istio实现应用的灰度发布
Istio为用户提供基于微服务的流量治理能力.Istio允许用户按照标准制定一套流量分发规则,并且无侵入的下发到实例中,平滑稳定的实现灰度发布功能. 基于华为云的Istio服务网格技术,使得灰度发布全 ...
- Sql中的主键和外键
SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...
- tkinter_战队数据查询系统
# 导入tkinter模块 import tkinter from tkinter import ttk # 导入库 import pymysql # 创建主窗口对象 root = tkinter.T ...
- hbase实践之写流程拾遗
keyvalue KeyValue中包含了丰富的自我描述信息: KeyValue是支撑"稀疏矩阵"设计的一个关键点:一些Key相同的任意数量的独立KeyValue就可以构成一行数据 ...
- Spring MVC + freemarker实现半自动静态化
这里对freemarker的代码进行了修改,效果:1,请求.do的URL时直接生成对应的.htm文件,并将请求转发到该htm文件2,自由控制某个页面是否需要静态化原理:对org.springframe ...
- 3、Spring Boot 2.x 核心技术
1.3 Spring Boot 核心技术 1.3.1 起步依赖 为项目的依赖管理提供帮助.起步依赖其实就是特殊的Maven,利用了传递依赖解析,把常用库聚合在一起,组成几个为特定功能而定制的依赖. 1 ...
- MySQL 5.7 GTID OOM bug案例分析 --大量压测后主从不同步
转载自:http://www.sohu.com/a/231766385_487483 MySQL 5.7是十年内最为经典的版本,这个观点区区已经表示过很多次.然而,经典也是由不断地迭代所打造的传奇.5 ...