#include <iostream>using namespace Std;template <class t>void qSort (T *a, int left, int. right);//Quick Sort Template <class t>void SW (t *a, t *b); int main () {int a[] = {3, 4, 5, 12,-1,-33, 90,-44,-23, 100,-1111, 9}; int len = sizeof (a)/sizeof (int); cout << * (a+1); cout << "raw data:" << Endl; for (int i = 0; I <len; ++i) cout << a[i] << ","; cout << Endl; QSort (A, 0, len-1); cout << "Fast post data:" << Endl; for (int i = 0; I <len; ++i) cout << a[i] << ",";} Template <class t>void qSort (T *a, int left, int.) {const int len = right; while (left < right) {while (* (A+left) < * (A+right) && left < right)--right; The first number of input queue is key, from right to left looking for smaller than key number, the current number is not smaller than key--right SW (A+left, a+right); while (* (A+left) < * (A+right) && left < right) ++left; From left to right to find a number larger than key, find after switching SW (A+left, a+right); QSort (A, 0, left-1); QSort (A, left+1, Len); }}template <class t>void SW (t *a, t *b) {T temp; temp = *a; *a = *b; *b = temp;}
Quickly sort C + + code