Code:
#include<iostream.h>
template<class T> void quickSort(T* a, int lo, int hi)
{
if (lo >= hi)
return;
T pivot = a[hi];
int i = lo - 1;
int j = hi;
while (i < j)
{
while (a[++i] < pivot) ;
while (j >= 0 && a[--j] > pivot) ;
if (i < j)
swap(&a[i],&a[j]);
}
swap(&a[i], &a[hi]);
quickSort(a, lo, i-1);
quickSort(a, i+1, hi);
}
template<class T> void sort(T* a, int n)
{
quickSort(a, 0, n-1);
}
template<class T> void swap(T *a, T *n)
{
T temp = *a;
*a = *n;
*n = temp;
}
int main()
{
const int n = 7;
int i;
int ary[n] = {9, 5, 1, 8, 3, 4, 6};
cout << " Before soring : ";
for( i = 0;i<n;++i)
cout << ary[i] << '\t';
sort(ary,n);
cout << "\n After sorting : ";
for( i=0;i<n;++i)
cout << ary[i] << '\t';
return 0;
}
If you really couldn't find the errors yourself, then you shouldn't be dealing with templates at this stage.