QuickSort

object QuickSort

In-place quicksort implementation. It is not stable, but does not allocate extra space (other than stack). Like MergeSort, it uses InsertionSort for sorting very small arrays.

class Object
trait Matchable
class Any

Value members

Concrete methods

@inline
final
def limit: Int
final
def partition[@specialized A : Order](data: Array[A], start: Int, end: Int, pivotIndex: Int): Int

Helper method for the quick sort implementation. Partitions the segment of the array data from start to end according to the value at the given pivotIndex. Values in the segment less than the pivot value will end up to the left of the pivot value, and values greater on the right. Operates in place.

Helper method for the quick sort implementation. Partitions the segment of the array data from start to end according to the value at the given pivotIndex. Values in the segment less than the pivot value will end up to the left of the pivot value, and values greater on the right. Operates in place.

Type Params
A

a member of the type class Order

Value Params
data

the array to be partitioned

end

the right endpoint (exclusive) of the interval to be partitioned

pivotIndex

the index of the current pivot

start

the left endpoint (inclusive) of the interval to be partitioned

Returns

the next pivot value

final
def qsort[@specialized A](data: Array[A], start: Int, end: Int)(implicit o: Order[A], ct: ClassTag[A]): Unit

Uses quicksort on data to sort the entries from the index start up to, but not including, the index end. Operates in place.

Uses quicksort on data to sort the entries from the index start up to, but not including, the index end. Operates in place.

If the size of the segment to be sorted is less than the threshold limit uses insertion sort instead.

Type Params
A

a member of the type class Order

Value Params
data

the array to be sorted

end

the index at which to stop sorting (exclusive)

start

the index from which to start sorting (inclusive)

final
def sort[@specialized A : ClassTag](data: Array[A]): Unit

Uses quicksort on data to sort the entries. Operates in place.

Uses quicksort on data to sort the entries. Operates in place.

If the size of the input array is less than the threshold limit, uses insertion sort instead.

Type Params
A

a member of the type class Order

Value Params
data

the array to be sorted