sort
#include <iostream>
#include <algorithm>
using namespace std;
template<typename T>
void mswap(T& t1,T& t2){
T t = t1;
t1 = t2;
t2 = t;
}
template<typename T>
void msort(T elems[],size_t cnt){
for(int i=0;i<cnt;i++){
bool isswap = false;
for(int j=1;j<cnt-i;j++){
if(elems[j] < elems[j-1]){
mswap(elems[j],elems[j-1]);
isswap = true;
}
}
if(!isswap){
break;
}
}
}
template<typename T>
void print(T elems[],size_t cnt){
for(int i=0;i<cnt;i++)
cout << elems[i] << " ";
cout << endl;
}
class Stu{
private:
int no;
string name;
int s;
public:
Stu(int no,string name,int s):no(no),name(name),s(s){}
int getNo()const{
return no;
}
int getS()const{
return s;
}
friend ostream& operator<<(ostream& os,const Stu& s);
};
ostream& operator<<(ostream& os,const Stu& s){
return os << s.no << " " << s.name << " " << s.s << endl;
}
class Comp{
public:
bool operator()(const Stu& s1,const Stu& s2){
return s2.getS() < s1.getS();
}
};
int main(){
int arr[9] = {7,2,9,8,1,4,5,0,6};
msort(arr,9);
print(arr,9);
Stu srr[5] = {Stu(110,"jack",90),Stu(120,"lily",97),
Stu(119,"lucy",89),Stu(127,"james",99),Stu(133,"jordan",97)};
sort(srr,srr+5,Comp());
print(srr,5);
return 0;
}