|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2016-3-28 17:09 编辑
- #include<list>
- #include<iostream>
- using namespace std;
- void printlist(const list<int>&listInput);
- bool SortPredicate_descending(const int& lsh, const int& rsh);
- int main()
- {
-
- list<int>list1;
- cout<<"please enter 5 numbers: "<<endl;
- int x[5];
- for(int i=0;i<5;i++)
- {
- cin>>x[i];
- list1.push_front(x[i]);
- }
- cout<<"Initial contents of list are :"<<endl;
- printlist(list1);
- list1.sort();
- cout<<"Order of elements after sort(): "<<endl;
- printlist(list1);
- list1.sort(SortPredicate_descending);
- cout<<"Order of elements after sort() with a predicate: "<<endl;
- printlist(list1);
- return 0;
- }
- void printlist(const list<int>&listInput)
- {
- if(listInput.size()>0)
- {
- cout<<"{";
- list<int>::const_iterator iElementlocator;
- for(iElementlocator=listInput.begin();iElementlocator!=listInput.end();++iElementlocator)
- cout<<*iElementlocator<<' ';
- cout<<"}";
- }
- else
- cout<<"List is empty!"<<endl;
- }
- bool SortPredicate_descending(const int& lsh, const int& rsh)
- {
- return(rsh<lsh);
- }
复制代码
只剩一个错误不会改,PS:我用的是VC6.0. |
|