#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. Image Processing and Analysis_21_Scale Space:Scale-space filtering——1987

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  2. vSphere

    VMware vSphere集成容器(VIC)建立了一个在轻量级虚拟机内部署并管理容器的环境.全新的虚拟机环境提供了更高级别的硬件隔离度,灵活性以及可扩展性使得容器对开发人员以及企业应用具有如此大的吸 ...

  3. 【javascript】h5页面禁止返回上一页

    window.history.pushState("","","#"); window.addEventListener("pop ...

  4. 开发神技能 | Python Mock 的入门

    Mock是什么 Mock这个词在英语中有模拟的这个意思,因此我们可以猜测出这个库的主要功能是模拟一些东西.准确的说,Mock是Python中一个用于支持单元测试的库,它的主要功能是使用mock对象替代 ...

  5. Nginx服务器的Websockets配置方法

    这篇文章主要介绍了简介Nginx服务器的Websockets配置方法,是使用Nginx服务器的网管的必备知识XD~需要的朋友可以参考下 Nginx 1.3.13 已经发布了,该版本支持 Connect ...

  6. TCP首部介绍

    每个T C P段都包含源端和目的端的端口号,用于寻找发端和收端应用进程.这两个值加上I P首部中的源端I P地址和目的端I P地址唯一确定一个T C P连接.有时,一个I P地址和一个端口号也称为一个 ...

  7. Java集合--TreeSet

    转载请注明出处:http://www.cnblogs.com/skywang12345/admin/EditPosts.aspx?postid=3311268 第1部分 TreeSet介绍 TreeS ...

  8. duilib学习领悟(2)

    再次强调,duilib只不过是一种思想! 在上一节中,我剖析了duilib中窗口类的注册,其中遗留两个小问题没有细说的? 第一个问题:过程函数中__WndProc()中有这么一小段代码: pThis ...

  9. JavaMail使用SMTP协议发送电子邮件(详解)

    Properties props = new Properties(); props.setProperty("mail.transport.protocol", "sm ...

  10. CF796D Police Stations BFS+染色

    题意:给定一棵树,树上有一些点是警察局,要求所有点到最近的警察局的距离不大于 $d$,求最多能删几条边 ? 题解: 考虑什么时候一条边可以被断开:这条边的两个端点被两个不同的警察局覆盖掉. 我们要设计 ...