public class QuickSort extends Object
List
of objects.
This class differs from sorting algorithms provided by the Arrays
and the Collections
classes:
Because this class does not allocate any temporary arrays, it uses indexed access
to the specified List
. Therefore it is important that specified List
has efficient implementations
of get(index)
and set(index, element)
operations.
If the order of the sorted element is not consistent, then the result of the operation is not necessarily sorted, but it is guaranteed to complete without exceptions.
Modifier and Type | Method and Description |
---|---|
static <T extends Comparable<? super T>> |
sort(List<T> list)
Sorts the specified list in ascending order according to the natural ordering of its elements.
|
static <T> void |
sort(List<T> list,
Comparator<? super T> c)
Sorts the specified list according to the order induced by the specified comparator.
|
static <T extends Comparable<? super T>> |
sort(List<T> list,
int from_index,
int to_index)
Sorts the specified range of the specified list in ascending order according to the natural ordering of its elements.
|
static <T> void |
sort(List<T> list,
int from_index,
int to_index,
Comparator<? super T> c)
Sorts the specified range of the specified list according to the order induced by the specified comparator.
|
static void |
sort(Object[] a)
Sorts the specified array in ascending order according to the natural ordering of its elements.
|
static void |
sort(Object[] a,
int from_index,
int to_index)
Sorts the specified range of the specified array in ascending order according to the natural ordering of its elements.
|
static <T> void |
sort(T[] a,
Comparator<? super T> c)
Sorts the specified array according to the order induced by the specified comparator.
|
static <T> void |
sort(T[] a,
int from_index,
int to_index,
Comparator<? super T> c)
Sorts the specified range of the specified array according to the order induced by the specified comparator.
|
public static void sort(Object[] a)
a
- the array to be sorted.public static <T> void sort(T[] a, Comparator<? super T> c)
a
- the array to be sorted.c
- the comparator to determine the order of the array. The 'null' value indicates 'natural ordering'.public static void sort(Object[] a, int from_index, int to_index)
a
- the array to be sorted.from_index
- the index of the first element (inclusive) to be sorted.to_index
- the index of the last element (exclusive) to be sorted.public static <T> void sort(T[] a, int from_index, int to_index, Comparator<? super T> c)
a
- the array to be sorted.from_index
- the index of the first element (inclusive) to be sorted.to_index
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the array. The 'null' value indicates 'natural ordering'.public static <T extends Comparable<? super T>> void sort(List<T> list)
list
- the list to be sorted.public static <T> void sort(List<T> list, Comparator<? super T> c)
list
- the list to be sorted.c
- the comparator to determine the order of the list. The 'null' value indicates 'natural ordering'.public static <T extends Comparable<? super T>> void sort(List<T> list, int from_index, int to_index)
list
- the list to be sorted.from_index
- the index of the first element (inclusive) to be sorted.to_index
- the index of the last element (exclusive) to be sorted.public static <T> void sort(List<T> list, int from_index, int to_index, Comparator<? super T> c)
list
- the list to be sorted.from_index
- the index of the first element (inclusive) to be sorted.to_index
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the array. The 'null' value indicates 'natural ordering'.Copyright © 2015 Devexperts. All Rights Reserved.