#includevoid quick_sort(int s[], int l, int r) { if (l < r) { int i = l, j = r, x = s[l]; while (i < j) { while (x <= s[j] && i < j) { j--; } s[i] = s[j]; while (x >= s[i] && i < j) { i++; } s[j] = s[i]; } s[i] = x; quick_sort(s, l, i - 1); quick_sort(s, i + 1, r); } } int main() { int s[] = { 2,8,5,6,3,9,4,0,7,1 }; int length; length = sizeof(s) / sizeof(s[0]); quick_sort(s, 0, length - 1); for (int i = 0; i < length; i++) { printf("%-2d", s[i]); } printf("n"); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)