1 #include<algorithm> 2 #include<iostream> 3 using namespace std; 4 void print(int x) 5 { 6 cout<<x<<' '; 7 } 8 int main() 9 { 10 int iArray[]={2,8,-15,90,26,7,23,30,-27,39,55}; 11 const int len=sizeof(iArray)/sizeof(int); 12 cout<<"由小到时大排序"<<endl; 13 sort(iArray,iArray+len); 14 for_each(iArray,iArray+len,print); 15 cout<<endl; 16 cout<<"由大到小排序"<<endl; 17 sort(iArray,iArray+len,greater<int>()); 18 for_each(iArray,iArray+len,print); 19 cout<<endl; 20 return 0; 21 }