#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. 从win到多系统

    相信有不少电脑爱好者喜欢折腾系统,尤其还是一个小白(感觉多系统强的不要不要的,各种崇拜),然后就走上了深渊. 首先,我一开始也是个win系统的忠实用户,没用过其他系统的我几乎不知道其他系统的存在,反正 ...

  2. pip安装超时:Read timed out.

    环境:win10 和 pip 在pip install h5py(或者其他第三方依赖包时) 会出现Read timed out.的问题,即安装超时.如下图所示: 解决方法: 1. 在用户目录下,新建p ...

  3. .NET Framework 概述

    文章标题:.NET Framework 概述 地址:https://docs.microsoft.com/zh-cn/dotnet/framework/get-started/overview NET ...

  4. linux tcp server bind

    如果不是系统管理员: bind()函数 返回失败

  5. JS不间断向上滚动 setInterval和clearInterval

    <div id=demo style=overflow:hidden;height:139;width:232;background:#f4f4f4;color:#ffffff><d ...

  6. Why Go? – Key advantages you may have overlooked

    Why Go? – Key advantages you may have overlooked yourbasic.org/golang Go makes it easier (than Java ...

  7. 0011SpringBoot的@EnableWebMvc全面接管SpringMVC的自动配置(源码)

    所谓的@EnableWebMvc全面接管SpringMVC的自动配置,是指@EnableWebMvc注解会使SpringMVC的自动配置失效,原理如下: 1.查看@EnableWebMvc的源码,如下 ...

  8. CSS3过渡动画&关键帧动画

    一.过渡动画 过渡(transition)动画,就是从初始状态过渡到结束状态这个过程中所产生的动画. 所谓的状态就是指大小.位置.颜色.变形(transform)等等这些属性. Note:不是所有属性 ...

  9. 甘特图控件如何自定义绘图?DevExpress Winforms帮你忙

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...

  10. express框架封装前戏

    一.开启一文件,这里暂且命名为aexpressclass.js 声明一个app类,用来模仿http模块中的回调函数 //var route = require('http-route'); var u ...