public class QuickSort extends Object
The notable differences of this Quick Sort from other sorting algorithms are:
In the case of unstable ordering the result of this algorithm is not necessarily fully sorted, but it is guaranteed to complete in a finite amount of time and without exceptions. The result in this case would be partially sorted to the best of algorithm's ability.
Modifier and Type | Method and Description |
---|---|
static void |
sort(int[] a,
IntComparator c)
Sorts the specified array of ints according to the order induced by the specified comparator.
|
static void |
sort(int[] a,
int fromIndex,
int toIndex,
IntComparator c)
Sorts the specified range of the specified array of ints according to the order induced by the specified comparator.
|
static <T extends Comparable<? super T>> |
sort(List<T> list)
Sorts the specified list into 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 fromIndex,
int toIndex)
Sorts the specified range of the specified list into ascending order according to the natural ordering of its elements.
|
static <T> void |
sort(List<T> list,
int fromIndex,
int toIndex,
Comparator<? super T> c)
Sorts the specified range of the specified list according to the order induced by the specified comparator.
|
static void |
sort(long[] a,
int fromIndex,
int toIndex,
LongComparator c)
Sorts the specified range of the specified array of longs according to the order induced by the specified comparator.
|
static void |
sort(long[] a,
LongComparator c)
Sorts the specified array of longs according to the order induced by the specified comparator.
|
static void |
sort(Object[] a)
Sorts the specified array of objects into ascending order according
to the natural ordering of its elements.
|
static void |
sort(Object[] a,
int fromIndex,
int toIndex)
Sorts the specified range of the specified array of objects into ascending order
according to the natural ordering of its elements.
|
static <T> void |
sort(T[] a,
Comparator<? super T> c)
Sorts the specified array of objects according to the order induced by the specified comparator.
|
static <T> void |
sort(T[] a,
int fromIndex,
int toIndex,
Comparator<? super T> c)
Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.
|
public static <T extends Comparable<? super T>> void sort(List<T> list)
Comparable
interface.
Furthermore, all elements in the list must be mutually comparable.T
- the class of the objects in the list.list
- the list to be sorted.ClassCastException
- if the list contains elements that are not mutually comparable.public static <T extends Comparable<? super T>> void sort(List<T> list, int fromIndex, int toIndex)
fromIndex
, inclusive, to index toIndex
, exclusive.
All elements in this range must implement the Comparable
interface.
Furthermore, all elements in this range must be mutually comparable.T
- the class of the objects in the list.list
- the list to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.IllegalArgumentException
- if fromIndex > toIndex
.IndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
.ClassCastException
- if the list contains elements that are not mutually comparable.public static <T> void sort(List<T> list, Comparator<? super T> c)
T
- the class of the objects in the list.list
- the list to be sorted.c
- the comparator to determine the order of the list. A null
value indicates
that the elements' natural ordering should be used.ClassCastException
- if the list contains elements that are not mutually comparable
using the specified comparator.public static <T> void sort(List<T> list, int fromIndex, int toIndex, Comparator<? super T> c)
fromIndex
, inclusive, to index toIndex
, exclusive.
All elements in the range must be mutually comparable by the specified comparator.T
- the class of the objects in the list.list
- the list to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the list. A null
value indicates
that the elements' natural ordering should be used.IllegalArgumentException
- if fromIndex > toIndex
.IndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
.ClassCastException
- if the list contains elements that are not mutually comparable
using the specified comparator.public static void sort(Object[] a)
Comparable
interface.
Furthermore, all elements in the array must be mutually comparable.a
- the array to be sorted.ClassCastException
- if the array contains elements that are not mutually comparable.public static void sort(Object[] a, int fromIndex, int toIndex)
fromIndex
, inclusive, to index toIndex
, exclusive.
All elements in this range must implement the Comparable
interface.
Furthermore, all elements in this range must be mutually comparable.a
- the array to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.IllegalArgumentException
- if fromIndex > toIndex
.IndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
.ClassCastException
- if the array contains elements that are not mutually comparable.public static <T> void sort(T[] a, Comparator<? super T> c)
T
- the class of the objects to be sorted.a
- the array to be sorted.c
- the comparator to determine the order of the array. A null
value indicates
that the elements' natural ordering should be used.ClassCastException
- if the array contains elements that are not mutually comparable
using the specified comparator.public static <T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
fromIndex
, inclusive, to index toIndex
, exclusive.
All elements in the range must be mutually comparable by the specified comparator.T
- the class of the objects to be sorted.a
- the array to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the array. A null
value indicates
that the elements' natural ordering should be used.IllegalArgumentException
- if fromIndex > toIndex
.IndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
.ClassCastException
- if the array contains elements that are not mutually comparable
using the specified comparator.public static void sort(int[] a, IntComparator c)
a
- the array to be sorted.c
- the comparator to determine the order of the array.public static void sort(int[] a, int fromIndex, int toIndex, IntComparator c)
fromIndex
, inclusive, to index toIndex
, exclusive.
All elements in the range must be mutually comparable by the specified comparator.a
- the array to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the array.IllegalArgumentException
- if fromIndex > toIndex
.IndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
.public static void sort(long[] a, LongComparator c)
a
- the array to be sorted.c
- the comparator to determine the order of the array.public static void sort(long[] a, int fromIndex, int toIndex, LongComparator c)
fromIndex
, inclusive, to index toIndex
, exclusive.
All elements in the range must be mutually comparable by the specified comparator.a
- the array to be sorted.fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the array.IllegalArgumentException
- if fromIndex > toIndex
.IndexOutOfBoundsException
- if fromIndex < 0
or toIndex > a.length
.Copyright © 2002–2025 Devexperts LLC. All rights reserved.