How do I make the function return the result of the sorted arrays?
class quiksort
{
public static char[] qsort(char[] items)
{
return qs(items, 0, items.Length - 1);
}
// A recursive version of Quicksort for characters.
static char[] qs(char[] items, int left, int right)
{
int i, j;
char x, y;
i = left; j = right;
x = items[(left + right) / 2];
do
{
while ((items[i] < x) && (i < right)) i++;
while ((x < items[j]) && (j > left)) j--;
if (i <= j)
{
y = items[i];
items[i] = items[j];
items[j] = y;
i++; j--;
}
} while (i <= j);
if (left < j)
{
return qs(items, left, j);
}
if (i < right)
{
return qs(items, i, right);
}
}
}
the errors says that not all code paths return a value? what does that mean
static T[] qs<T>(T[] items, int left, int right) where T : IComparable<T>. You would only have to replacecharwithTand the<operator with theCompareTo()method fromIComparable.