标签:printf print array pivot class for div quicksort size
void QuickSort(int nLow, int nHigh) { int s = nLow; int e = nHigh; int nPivot = nLow; if (s >= e) { return; } while (1) { while (g_szArray[nLow] <= g_szArray[nPivot] && nLow <= e) { nLow++; } while (g_szArray[nHigh] > g_szArray[nPivot] && nHigh >= s) { nHigh--; } if (nLow > nHigh) { break; } else { g_szArray[nLow] = g_szArray[nLow] + g_szArray[nHigh]; g_szArray[nHigh] = g_szArray[nLow] - g_szArray[nHigh]; g_szArray[nLow] = g_szArray[nLow] - g_szArray[nHigh]; nLow++; nHigh--; } } /*g_szArray[nHigh] = g_szArray[nPivot] + g_szArray[nHigh]; g_szArray[nPivot] = g_szArray[nHigh] - g_szArray[nPivot]; g_szArray[nHigh] = g_szArray[nHigh] - g_szArray[nPivot];*/ int nTmp = g_szArray[nHigh]; g_szArray[nHigh] = g_szArray[nPivot]; g_szArray[nPivot] = nTmp; QuickSort(nLow, e); QuickSort(s, nLow - 1); } void main() { int nLen = sizeof(g_szArray) / sizeof(g_szArray[0]); QuickSort(0, nLen - 1); for (int i = 0; i < nLen; i++) { printf("%d ", g_szArray[i]); } printf("\n"); system("pause"); }
标签:printf print array pivot class for div quicksort size
原文地址:https://www.cnblogs.com/predator-wang/p/11925654.html