/* QuickSort.hpp */
#ifndef _QUICK_SORT_H_
#define _QUICK_SORT_H_
template<typename T>
void QuickSort(T *pInput, int low, int high)
{
if(low >= high)
{
return;
}
int first = low;
int last = high;
int key = pInput[first];
while(first < last)
{
while(first<last && pInput[last]>=key)
{
--last;
}
pInput[first] = pInput[last];
while(first<last && pInput[first]<=key)
{
++first;
}
pInput[last] = pInput[first];
}
pInput[first] = key;
QuickSort(pInput,low,first-1);
QuickSort(pInput,first+1,high);
}
#endif
/* main.cpp */
#include <iostream>
#include "QuickSort.hpp"
using namespace std;
int main()
{
int i = 0;
int a[10] = {1,4,7,2,5,8,3,6,9,0};
QuickSort<int>(a,0,9);
for(i=0; i<10; i++)
{
cout<<a[i]<<'\t';
}
cout<<endl;
return 0;
}