First step is to actually use generics:
void QuickSort<T>(T[] array, ...)
and
int Partition<T>(T[] array, ...)
In Partition
remove the generic argument from Swap
. It will be inferred by the compiler.
However, for this to work, you need to constrain T
to IComparable<T>
:
void QuickSort<T>(T[] array, ...) where T : IComparable<T>
and
int Partition<T>(T[] array, ...) where T : IComparable<T>
Finally, you need to replace the "less than" and "greater than" operators with calls to CompareTo
:
if(array[midPoint].CompareTo(array[lowerBound]) < 0)
and
if(array[midPoint].CompareTo(array[lowerBound]) > 0)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…