C++, merge sort using self-define comparator
Mention that when sorting the digits-logs, we can\'t simply use sort()! Since sort() is based on unstable Quick-sort algorithm, equivalent elements are not guar
Mention that when sorting the digits-logs, we can\'t simply use sort()! Since sort() is based on unstable Quick-sort algorithm, equivalent elements are not guaranteed to keep their original relative order. Here we use Merge-sort based algorithm: stable_sort() to solve this issue.\n```\nclass Solution {\npublic:\n    static bool cmp(const string &a, const string &b){\n        int i = a.find(\' \');\n        int j = b.find(\' \');            \n        if(a[i+1]-\'0\' >= 10 and b[j+1]-\'0\' >= 10){//two letter-logs\n            if(a.substr(i+1)==b.substr(j+1)){\n                return a.substr(0,i) < b.substr(0,j);\n            }\n            else return a.substr(i+1) < b.substr(j+1);\n        }\n        else if(a[i+1]-\'0\' < 10 xor b[j+1]-\'0\' < 10){// one digit-log, one letter-log\n            if(a[i+1]-\'0\' > 10) return true; //a is letter-log, come before b.\n            else return false;\n        }\n        return false;\n    }\n    vector<string> reorderLogFiles(vector<string>& logs) {\n        stable_sort(logs.begin(),logs.end(),cmp);\n        return logs;\n    }\n};\n```
['C']