鱼C论坛

 找回密码
 立即注册
查看: 1892|回复: 2

一个C++list问题

[复制链接]
发表于 2016-3-28 16:27:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 ~风介~ 于 2016-3-28 17:09 编辑
  1. #include<list>
  2. #include<iostream>
  3. using namespace std;
  4. void printlist(const list<int>&listInput);
  5. bool SortPredicate_descending(const int& lsh, const int& rsh);
  6. int main()
  7. {
  8.        
  9.         list<int>list1;
  10.         cout<<"please enter 5 numbers: "<<endl;
  11.         int x[5];
  12.         for(int i=0;i<5;i++)
  13.         {
  14.                 cin>>x[i];
  15.                 list1.push_front(x[i]);
  16.         }
  17.         cout<<"Initial contents of list are :"<<endl;
  18.         printlist(list1);
  19.         list1.sort();
  20.         cout<<"Order of elements after sort(): "<<endl;
  21.         printlist(list1);
  22.         list1.sort(SortPredicate_descending);
  23.         cout<<"Order of elements after sort() with a predicate: "<<endl;
  24.         printlist(list1);
  25.         return 0;

  26. }
  27. void printlist(const list<int>&listInput)
  28. {
  29.         if(listInput.size()>0)
  30.         {
  31.                 cout<<"{";
  32.                 list<int>::const_iterator iElementlocator;
  33.                 for(iElementlocator=listInput.begin();iElementlocator!=listInput.end();++iElementlocator)
  34.                         cout<<*iElementlocator<<' ';
  35.                 cout<<"}";
  36.         }
  37.         else
  38.                 cout<<"List is empty!"<<endl;
  39. }
  40. bool SortPredicate_descending(const int& lsh, const int& rsh)
  41. {
  42.         return(rsh<lsh);
  43. }
复制代码

只剩一个错误不会改,PS:我用的是VC6.0.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-3-30 16:11:40 | 显示全部楼层
vs2010没有错误,没有警告。玩模板建议不要用vc6.0吧,起码不支持c++11标准
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-3-30 17:22:50 | 显示全部楼层
我后来在VS试了可以使用。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-25 17:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表