本文共 1114 字,大约阅读时间需要 3 分钟。
void PrintMinNumber(int* numbers, int length){ if(numbers == NULL || length <= 0) return; char** strNumbers = (char**)(new int[length]); for(int i = 0; i < length; ++i) { strNumbers[i] = new char[g_MaxNumberLength + 1]; sprintf(strNumbers[i], "%d", numbers[i]); } qsort(strNumbers, length, sizeof(char*), compare); for(int i = 0; i < length; ++i) printf("%s", strNumbers[i]); printf("\n"); for(int i = 0; i < length; ++i) delete[] strNumbers[i]; delete[] strNumbers;} // 如果[strNumber1][strNumber2] > [strNumber2][strNumber1], 返回值大于0// 如果[strNumber1][strNumber2] = [strNumber2][strNumber1], 返回值等于0// 如果[strNumber1][strNumber2] < [strNumber2][strNumber1], 返回值小于0int compare(const void* strNumber1, const void* strNumber2){ // [strNumber1][strNumber2] strcpy(g_StrCombine1, *(const char**)strNumber1); strcat(g_StrCombine1, *(const char**)strNumber2); // [strNumber2][strNumber1] strcpy(g_StrCombine2, *(const char**)strNumber2); strcat(g_StrCombine2, *(const char**)strNumber1); return strcmp(g_StrCombine1, g_StrCombine2);}