1. ## Quick Sorting ?!?!?

Hi!
I am really in trouble with this code
I am not sure where is the mistake. Waiting for some good help

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);
}

int main()
{
const int n = 7;

int ary[n] = {9, 5, 1, 8, 3, 4, 6};

cout << " Before soring : ";

for(int i=0;i<n;++i)
cout << ary[i] << '\t';

sort(ary,n);

cout << "\n After sorting : ";

for(int i=0;i<n;++i)
cout << ary[i] << '\t';

return 0;
}```

2. 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.

3. Sorry! I thought It would work!
Code:
```#include <algorithm>

template <class T>
void swap (T& a, T& b);```
But I didn't included it!!!
Now will it be ok?

4. How can I make many of my functions within TEMPLATEs ?