Converting Quick sort to template

My whole code is included below, although what is really important to me is only the first two functions, the quicksort and the partition...
Whenever I build this program, it keeps returning an error for the calling of the partition function, citing that the first variable is in an improper format... I don't know why it's not working though... Can anybody help?


Whole Code:
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

template <class T>
void quicksort(T arr[], int start, int end) {
if (start < end) //test for base case start == end
{
// Partition the array and get the pivot point.
int p = partition(arr, start, end);

// Sort the portion before the pivot point.
quicksort(arr, start, p - 1);

// Sort the portion after the pivot point.
quicksort(arr, p + 1, end);
}
return;
}

template <class T>
int partition(T arr[], int start, int end)
{
// The pivot element is taken to be the element at
// the start of the subrange to be partitioned.
T pivotValue = arr[start];
int pivotPosition = start;

// Rearrange the rest of the array elements to
// partition the subrange from start to end.
for (int pos = start + 1; pos <= end; pos++)
{
if (arr[pos] < pivotValue)
{
// arr[pos] is the "current" item.
// Swap the current item with the item to the
// right of the pivot element.
swap(arr[pivotPosition + 1], arr[pos]);
// Swap the current item with the pivot element.
swap(arr[pivotPosition], arr[pivotPosition + 1]);
// Adjust the pivot position so it stays with the
// pivot element.
pivotPosition ++;
}
}
return pivotPosition;
}

template <class T>
void print(T arr[], int size){
cout << "These are the members of the array: \n";
for (int i = 0; i < size; i++) {
cout << arr[i] << endl;
}
return;
}

int main()
{
int arrayInt[50];
string arrayString[50];
char arrayChar[50];
double arrayDouble[50];
int choice, size;
cout << "\t\tPress 1 to enter in an array of integers.\n";
cout << "\t\tPress 2 to enter in an array of strings.\n";
cout << "\t\tPress 3 to enter in an array of characters.\n";
cout << "\t\tPress 4 to enter in an array of doubles.\n";
cin >> choice;
cout << "Please enter how many pieces of data you want to input: ";
cin >> size;
switch (choice) {
case 1:
for (int i = 0; i < size; i++)
cin >> arrayInt[i];
quicksort(arrayInt, 0, size-1);
print(arrayInt, size - 1);
break;
case 2:
for (int i = 0; i < size; i++)
cin >> arrayString[i];
quicksort(arrayString, 0, size-1);
print(arrayString, size);
break;
case 3:
for (int i = 0; i < size; i++)
cin >> arrayChar[i];
quicksort(arrayChar, 0, size-1);
print(arrayChar, size);
break;
case 4:
for (int i = 0; i < size; i++)
cin >> arrayDouble[i];
quicksort(arrayDouble, 0, size - 1);
print(arrayDouble, size);
break;
default:
cout << "\nPlease enter a choice.\n";
}
return 0;
}
Please use code tags: http://www.cplusplus.com/forum/articles/42672/

Move your partition template ahead of the quicksort template. With the order that have them the compiler is using std::partition in quicksort because your version of partition is not yet defined.
Registered users can post here. Sign in or register to post.