sort 函数 cmp 辅助排序

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 int n,tc;
 5 int a[5]={3,1,5,4,9};
 6 int b[5]={0,1,2,3,4};
 7 bool cmp(const int& i,const int& j)
 8 {
 9     return a[i]<a[j];
10 }
11 int main()
12 {    
13     sort(b,b+5,cmp);
14     for(int i=0;i<5;++i)
15         cout<<b[i]<<" "<<a[i]<<endl;   
16     for(int i=0;i<5;++i)
17         cout<<a[b[i]]<<" "<<a[i]<<endl;    
18     
19     return 0;
20 }

 

posted @ 2013-12-13 22:51  y丫t  阅读(255)  评论(0编辑  收藏  举报