#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的更多相关文章

  1. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  2. [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写

    A string such as "word" contains the following abbreviations: ["word", "1or ...

  3. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  4. [LeetCode] Unique Word Abbreviation 独特的单词缩写

    An abbreviation of a word follows the form <first letter><number><last letter>. Be ...

  5. [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  6. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  7. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  8. [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 ...

  9. 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 ...

  10. Constraint5:unique 约束和null

    unique约束使用unique index来限制列值的唯一性: 创建unique约束之后,column中允许插入null值,unique 约束将两个null值看作是相同的(即null=null为tr ...

随机推荐

  1. 【OGG 故障处理】 丢失归档恢复

    OGG 有两天由于某种原因没有启动,而这段时间的备份文件缺失了一部分归档.恢复过程记录如下: GGSCI (xxxx) > info all Program Status Group Lag a ...

  2. Vs2017 NetCode Mvc EF Mysql 整合1

    1  运行环境   vs2017   NetCode2.0 2 NuGet  MySql.Data.EntityFrameworkCore 8.0.18 3  源代码 https://github.c ...

  3. Const *ptr ptr

    1. const int *ptr = NULL; <=> int const *ptr = NULL; 1) 表示指向符号常量的指针变量,指针变量本身并非const所以可以指向其他变量. ...

  4. pyecharts各省人口GDP可视化分析

    版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/82503569 9月9日更:本篇博客数据下载:链接:http ...

  5. n诺挑战赛5题解

    Drinking 题意:就是给你n瓶酒的初始伤害值,第几天喝这瓶酒伤害值就是这瓶酒的初始伤害值第几倍,而且他每天喝的瓶数不超过m.要你输出所有的情况,就是他喝(1~n)瓶的伤害值的最小, 思路:就是这 ...

  6. 【Leetcode】【简单】【283. 移动零】【JavaScript】

    题目描述 283. 移动零 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序. 示例: 输入: [0,1,0,3,12]输出: [1,3,12,0,0] 说 ...

  7. Spring Bean装配(下)——注解

    @Repository,@Service,@Controller这三个注解是基于component定义的注解 component-scan:组件扫描 base-package:扫描这个下的所有类 &l ...

  8. list交集

    在C#语言程序设计中,List集合是常用的集合数据类型,在涉及集合类型的运算中,有时候我们需要计算2个List集合中共有的数据,即对2个List集合求交集运算.此时可以使用C#语言提供的Interse ...

  9. JQuery中 text()、html() 以及 val()以及innerText、innerHTML和value

    设置内容 - text().html() 以及 val() 我们将使用前一章中的三个相同的方法来设置内容: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容( ...

  10. http响应Last-Modified和ETag

    http响应Last-Modified和ETag [日期:2008-06-16] 来源:  作者: [字体:大 中 小] 基础知识 1) 什么是”Last-Modified”? 在浏览器第一次请求某一 ...