十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
void CountSort(int* a, int n) { assert(a); int minValue = a[0]; int maxValue = a[0]; for (int i = 0; i < n; ++i) { if (minValue > a[i]) { minValue = a[i]; } if (maxValue < a[i]) { maxValue = a[i]; } } int range = maxValue-minValue+1; int* tmp = new int[range]; memset(tmp, 0, sizeof(int)*range); int index = 0; while (index < n) { tmp[a[index]-minValue]++; ++index; } index = 0; for (int i = 0; i < range; ++i) { while (tmp[i]--) { a[index++] = i+minValue; } } delete[] tmp; }