#include "stdafx.h" void PrintFunc(int a[], int n) { for (int i = 0; i < n;i++) { printf("%d ", a[i]); } printf(" "); } //快速排序 int QSort(int a[], int n) { int low = 0; int high = n - 1; int tmp, j; while (low < high) { for (j = low; j < high;++j) { if (a[j+1]<a[j]) { tmp = a[j]; a[j] = a[j +1]; a[j + 1] = tmp; } } high--; for (j = high;j>low; --j) { if (a[j]<a[j-1]) { tmp = a[j]; a[j] = a[j - 1]; a[j - 1] = tmp; } } ++low; PrintFunc(a, n); } return 0; } int _tmain(int argc, _TCHAR* argv[]) { int a[] = {9,8,7,6,5,4,3,2,1, 0}; //InsertSort(a, 10); QSort(a, 10); //PrintFunc(a, 10); return 0; }
Out:
E:Debug>AlgoTest.exe
0 8 7 6 5 4 3 2 1 9
0 1 7 6 5 4 3 2 8 9
0 1 2 6 5 4 3 7 8 9
0 1 2 3 5 4 6 7 8 9
0 1 2 3 4 5 6 7 8 9