在c++中,快排(sort)的cmp函数,返回0和-1有什么区别?
我在做题时,返回0就对了,返回-1就错了。
bool cmp(Student x,Student y){
if(x.year<y.year) return 1;
if(x.year>y.year) return 0;
if(x.year==y.year){
if(x.mon<y.mon) return 1;
if(x.mon>y.mon) return 0;
if(x.mon==y.mon){
if(x.day<y.day) return 1;
if(x.day>y.day) return 0;
if(x.day==y.day){
if(x.num>y.num) return 1;
else return 0;
}
}
}
}
我在做题时把return 0全改成return -1就排错了。