标签:
关于算法中的比较函数
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 int compare(double a,double b){ 5 return a>b; 6 } 7 int main(){ 8 double a[10]={2.15,2.14,3.11,3.1010001,5,8,46,5,45,10}; 9 double b[10]={2.15,2.14,3.11,3.1010001,5,8,46,5,45,10}; 10 sort(a,a+10,compare); 11 sort(b,b+10); 12 for(int i=0;i<10;i++) 13 cout<<a[i]<<" "; 14 cout<<endl; 15 for(int i=0;i<10;i++) 16 cout<<b[i]<<" "; 17 return 0; 18 }
比较函数中传入的形参要和所排序的数的类型一样.
标签:
原文地址:http://www.cnblogs.com/bingdada/p/5466496.html