Home > Back-end >  C who help me: sort custom compare function caused abnormal
C who help me: sort custom compare function caused abnormal

Time:04-13

If sort using myCompare program run normally, and using the MC will quote: pass an invalid parameter to the invalid parameter is regarded as serious error function is unusual,
This is why, & amp; How to debug the error to find the problem?

The class Solution1 {
The static bool myCompare (string x, string y) {//descending
Return x + y & gt; Y + x;

}
The static bool MC (string x, string y) {
Return (x + y). Compare (y + x);
}
String largestNumber (vector & Nums) {

Vector NumStr;
A string of Max;
For (auto iter=nums. The begin (); iter !=nums. End (); Iter++)
NumStr. Push_back (to_string iter) (*).
Sort (numStr. The begin (), numStr end (), myCompare);//an error here!!!!!!!!!!!
A: for (auto numStr) {
Max +=a;
}
If (Max [0]=='0') return "0".
The return of Max;

}

};

CodePudding user response:

Compare not so use it only 0 is equal is other nonzero are true or false

CodePudding user response:

An error could be the negative turn bool guess

CodePudding user response:

Sort the comparison function must be a function pointer, a lambda expressions, a function, that each of you nothing, so wrong,
Specific baidu STL: : sort comparison function
  • Related