Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > stl----sort 与unique的调用次序和unique的用法
【标  题】:stl----sort 与unique的调用次序和unique的用法
【关键字】:stl----sort,unique,unique
【来  源】:http://www.cppblog.com/mzty/archive/2005/12/14/1743.html

stl----sort 与unique的调用次序和unique的用法

Your Ad Here

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;

 

int main()
{
 
 int source[] = { 1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7,
  5, 4, 4 };
 int sourceNum = sizeof(source)/sizeof(source[0]);

 vector<int> coll;

  
  copy (source, source+sourceNum,               //source
  back_inserter(coll)) ;                  //destination

  copy (coll.begin(), coll.end(), ostream_iterator<int>(cout," "));
  cout << "\n\n";

  sort(coll.begin(),coll.end());

 
 vector<int> :: iterator pos;
 pos = unique (coll.begin(), coll.end());
 copy (coll.begin(), coll.end(), ostream_iterator<int>(cout," "));
 cout << "\n\n";

 
 copy (coll.begin(), pos, ostream_iterator<int>(cout," "));     
 cout << "\n\n";

 
 copy (source, source+sourceNum,coll.begin());      

                 

 copy (coll.begin(), coll.end(),ostream_iterator<int>(cout," "));
 cout << "\n\n";

 //remove elements if there was a previous greater element
 coll.erase (unique (coll.begin(), coll.end(),greater<int>()), coll.end());
 
 copy (coll.begin(), coll.end(), ostream_iterator<int>(cout," "));
 cout << "\n\n";
}



----------------------------------------
但是当要比较的数为计算所的的一个double,不能用sort和unique,怎么办?有没有好的办法啊!谢谢!

比如要比较的vector是从屏幕是得到的点的x坐标!坐标是通过鼠标时时得到!
要得到所有的不同的点的x坐标?

(可以用近似的算法)

函数对象:【上一篇】
你也许还没用过的vc++的调试的功能:【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • John the Ripper -----------密码破解专家
  • 硬件技术工程师之我学(1)
  • 网上开店免费系统
  • where can i download the sun solaris patch?
  • 为什么发表一篇文章就要一个标题? why,why,why
  • Castle ActiveRecord 访问 Oracle 的几个应注意之处
  • 规范化查询模式并建立与之匹配的索引
  • PS技巧167条
  • 初探Quartz的扩展
  • 轻松打造自己的Visual C++ 2005 Express Edition Beta 2
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.