class Student{
public:
string x;
};
我怎麼按由大到小的順序排序啊?
sort沒用的說,求大神詳細代碼!
#include<iostream>
#include<algorithm>
using namespace std;
class Student{
public:
string x;
};
short comp(const Student &a,const Student &b)
{
return a.x>b.x;
}
int main()
{
Student a[5];
int i;
for(i=0;i<5;i++)
cin>>a[i].x;
sort(a+0,a+5,comp);
for(i=0;i<5;i++)
cout<<a[i].x<<" ";
cout<<endl;
}