int cmp(const void* a, const void* b){ return *(int*)a - *(int*)b; } int** minimumAbsDifference(int* arr, int arrSize, int* returnSize, int** returnColumnSizes){ int i,min=2000001,pst=0; int** RetArr = (int**)malloc(arrSize*sizeof(int*)); int *retColSize = (int*)malloc(arrSize * sizeof(int)); //这题必须新分配列空间 如果在*returnColumnSizes直接改列数返回出错 qsort(arr,arrSize,sizeof(int),cmp); for (i=0; i<arrSize-1; i++) { if (abs(arr[i] - arr[i+1]) <= min) { if (abs(arr[i] - arr[i+1]) < min) { pst=0; min = abs(arr[i] - arr[i+1]); } RetArr[pst] = (int*)malloc(2*sizeof(int)); RetArr[pst][0] = arr[i]; RetArr[pst][1] = arr[i+1]; retColSize[pst++] = 2; } } *returnColumnSizes = retColSize; *returnSize = pst; return RetArr; }