- #include<bits/stdc++.h>
- using namespace std;
- int n[]= {5,7,3,9,8,1,2,4,6};
- int len=sizeof(n)/sizeof(int);
- bool compare(int a, int b)
- {
- return a>b;
- }
- void show(){
- cout<<"-----------------"<<endl;
- for(int i: n)
- cout<<i<<" ";
- cout<<endl;
- }
- int main()
- {
- show();
- sort(n,n+len);
- //sort(begin(n),end(n));
- show();
- //sort(rbegin(n),rend(n));
- //sort(begin(n),end(n),greater<int>()); //less<int>()
- sort(n,n+len,compare);
- show();
- return 0;
- }
複製代碼 |