template <class DataType>
void Array<DataType>::sort(int left, int right)
{
int i = left, j = right;
DataType temp;
DataType pivot = (*this)[(left + right) / 2];
while (i <= j)
{
while ((*this)[i] < pivot)
i++;
while ((*this)[j] > pivot)
j--;
if (i <= j)
{
temp = (*this)[i];
(*this)[i] = (*this)[j];
(*this)[j] = temp;
i++;
j--;
}
}
if (left < j)
sort(left, j);
if (i < right)
sort(i, right);
}
here's my quicksort, problem is it only seems to work with integers, I'm trying to make this work for a templated array with an object with ONLY the less-than overloaded operator programmed in. Any suggestions as to how to get this to work would be appreciated
Here ya go, trying to use it to sort an array of this type, but it calls a compiler error
I get if I were to overload an operator> I'd fix it, but I'm trying to get it to not require an operator>. Any suggestions would be helpful. In other words this would require a change of the sort function and not of the object itself.
@Athar: "Then you shouldn't use greater than." That's why I'm asking for help! Trying to fix the sort function so I don't use it!
@Athar: It's a quicksort code in a templated array.
All I really need is pseudocode or an algorithm for a generic quicksort function that doesn't require a "greater than" while statement or separate "pivot" or "swap" functions. I've tried googling generic quicksort functions but it's been rather unhelpful. Or better yet simply a way to bypass a "greater than" while statement
and.....I'm an idiot lol, I tried it before but it kept throwing errors, now it's working, must've typo'd it or something. Thanks for dealing with me ^_^