stl中sort的排序从大到小怎么排
#include<iostream>#include<list>#include<algorithm>usingnamespacestd;intmain(){inta[]...
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort();
//l1.sort(l1.begin(),l1.end(),greater<int>);
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return 0;
}
就是用容器从大到小怎么排啊 直接贴图 谢谢啊(急!急!急!)
stl中有的函数括号中是op例如sort(op),unique(op)意思明白就是不会用那位给讲讲啊 最好是把他们的从大到小用例子贴出来 谢谢啊 展开
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort();
//l1.sort(l1.begin(),l1.end(),greater<int>);
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return 0;
}
就是用容器从大到小怎么排啊 直接贴图 谢谢啊(急!急!急!)
stl中有的函数括号中是op例如sort(op),unique(op)意思明白就是不会用那位给讲讲啊 最好是把他们的从大到小用例子贴出来 谢谢啊 展开
展开全部
#include <list>
#include <iostream>
using namespace std;
int main( )
{
list <int> c1;
list <int>::iterator c1_Iter;
int num,var;//for input num and var for the list
cout << "输入需要排序的个数:" ;
cin >> num;
for(int i=0;i<num;i++)
{
var = 0;
cout << "输入第" << i+1 << "个数:";
cin >> var;
c1.push_back(var);
}
cout << "排序前:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
c1.sort( );
cout << "排序后:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
c1.sort( greater<int>( ) );//注意这行
cout << "按照降序重新排序是:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
// cin >> num; //留住屏幕结果
return 0;
}
#include <iostream>
using namespace std;
int main( )
{
list <int> c1;
list <int>::iterator c1_Iter;
int num,var;//for input num and var for the list
cout << "输入需要排序的个数:" ;
cin >> num;
for(int i=0;i<num;i++)
{
var = 0;
cout << "输入第" << i+1 << "个数:";
cin >> var;
c1.push_back(var);
}
cout << "排序前:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
c1.sort( );
cout << "排序后:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
c1.sort( greater<int>( ) );//注意这行
cout << "按照降序重新排序是:";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
// cin >> num; //留住屏幕结果
return 0;
}
展开全部
你只是sort写法错了
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort(greater<int>());
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return 0;
}
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort(greater<int>());
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort();
l1.reverse();
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return 0;
}
或者
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::reverse_iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort();
for(p=l1.rbegin();p!=l1.rend();p++)
cout<<*p;
cout<<endl;
return 0;
}
最简单办法~
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort();
l1.reverse();
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return 0;
}
或者
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(){
int a[]={8,2,3,1,9};
list<int>l1;
list<int>::reverse_iterator p;
for(int i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort();
for(p=l1.rbegin();p!=l1.rend();p++)
cout<<*p;
cout<<endl;
return 0;
}
最简单办法~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你只是sort写法错了
#include<iostream>
#include<list>
#include<algorithm>
using
namespace
std;
int
main(){
int
a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator
p;
for(int
i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort(greater<int>());
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return
0;
}
#include<iostream>
#include<list>
#include<algorithm>
using
namespace
std;
int
main(){
int
a[]={8,2,3,1,9};
list<int>l1;
list<int>::iterator
p;
for(int
i=0;i<5;i++)
l1.push_back(a[i]);
l1.sort(greater<int>());
for(p=l1.begin();p!=l1.end();p++)
cout<<*p;
cout<<endl;
return
0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询