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 ...
随机推荐
- OSI七层与TCP/IP五层
OSI七层与TCP/IP五层网络架构详解 OSI和TCP/IP是很基础但又非常重要的网络基础知识,理解得透彻对运维工程师来说非常有帮助.今天偶又复习了一下: (1)OSI七层模型 OSI中的层 功能 ...
- MVVM框架-MVVMLight
项目URL:http://www.mvvmlight.net/ 一.安装MVVMLight 在NuGet程序包中搜索MVVMLight,然后安装. 二.使用 安装完MVVMLight后项目中会自动生成 ...
- Golang 本身是用什么语言写的?
原文:https://www.zhihu.com/question/66944175 ------------------------------- 首先,问题的说法是有问题的. golang本身是用 ...
- 字符串的新方法——includes() padStart() padEnd()
ES6为字符串提供了一个新方法,叫做String.prototype.includes('要包含的字符串'),如果包含,则返回字符串,否则返回false 使用ES6中的字符串新方法String.pro ...
- 性能一 Exploring Mobile vs. Desktop OpenGL Performance
opengl insight Exploring Mobile vs. DesktopOpenGL Performance Jon McCaffrey 前面那些内容以前看过 应该写在谋篇帖子里了 F ...
- c#截图功能
简化版: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- 使用@ConfigurationProperties注解 提示 “Spring Boot Configuration Annotation Processor not found in classpath ”
解决方案: 在 pom.xml 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...
- Java8-Lock-No.01
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...
- C语言学习系列(一)开门首篇
一.特辑 此次是我自己的学习之路,和大家一起分享(我现在是做Java),途中遇到什么问题大家也可以提出来一起讨论一起进步: 主要参考教程是菜鸟教程上面的C语言教程,以及大学课本C语言教程-第四版(谭浩 ...
- linux下core dump--转载
原文链接:https://www.cnblogs.com/Anker/p/6079580.html 1.前言 一直在从事linux下后台开发,经常与core文件打交道.还记得刚开始从事linux下 ...