zoukankan      html  css  js  c++  java
  • unique &unique_copy

     

    unique (ForwardIterator first, ForwardIterator last);

    unique (ForwardIterator first, ForwardIterator last, BinaryPredicate pred);

    类属性算法unique的作用是从输入序列中“删除”所有相邻的重复元素。该算法删除相邻的重复元素(不相邻的元素无法删除),

    然后重新排列输入范围内的元素(没有进行排序,按照原序列排列),并且返回一个迭代器(容器的长度没变,只是元素顺序

    改变了),表示无重复的值范围得结束。

    unique_copy (InputIterator first, InputIterator last,OutputIterator result);

    unique_copy (InputIterator first, InputIterator last,OutputIterator result, BinaryPredicate pred);

    unique_copy 唯一的区别在于:unique_copy 接受第三个迭代器实参,用于指定复制不重复元素的目标序列。

    ex:

    // unique algorithm example
    #include <iostream>     
    #include <algorithm> #include <vector> bool myfunction (int i, int j) { return (i==j); } int main () { int myints[] = {10,20,20,20,30,30,20,20,10}; // 10 20 20 20 30 30 20 20 10 std::vector<int> myvector (myints,myints+9); // using default comparison: std::vector<int>::iterator it; it = std::unique (myvector.begin(), myvector.end()); // 10 20 30 20 10 ? ? ? ? // ^ myvector.resize( std::distance(myvector.begin(),it) ); // 10 20 30 20 10 // using predicate comparison: std::unique (myvector.begin(), myvector.end(), myfunction); // (no changes) // print out content: std::cout << "myvector contains:"; for (it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << *it; std::cout << ' '; return 0; }
  • 相关阅读:
    HAL 分析
    Ubuntu 11.04 安装后要做的20件事情
    IOStableViewCell自适应高度cell里面放的是UIlable
    IOS支持的字体
    IOS TableView学习资源
    产品与市场
    软件质量与公司盈利
    计算机流派
    让你的软件支持繁体中文
    系统规划设置心得
  • 原文地址:https://www.cnblogs.com/Mr-Zhong/p/4551094.html
Copyright © 2011-2022 走看看