Fix index check in QuickSort algorithm