sort函数

#include <iostream>
#include<algorithm>
using namespace std;

int a[5];

int main( )
{
int i;
for(i=0;i<5 ;i++) cin>>a[i] ;
sort(a,a+5);
for(i=0;i<5 ;i++) cout<<a[i]<<" " ;
cout<<endl;
}

 

 

 

 

 

 

 

***********************************************************************************

 

#include <iostream>
#include<algorithm>
using namespace std;

int a[5];
bool cmp( const int &a,const int &b)
{ if(a!=b) return a>b; else return a>b ; }

int main( )
{
int i;
for(i=0;i<5 ;i++) cin>>a[i] ;
sort(a,a+5,cmp);
for(i=0;i<5 ;i++) cout<<a[i]<<" " ;
cout<<endl;

}

 

 

 

posted @ 2014-08-10 17:21  2014acm  阅读(123)  评论(0编辑  收藏  举报