- All Implemented Interfaces:
ComparisonSortAlgorithm<Object>,SortAlgorithm<Object>
http://www.auto.tuwien.ac.at/~blieb/woop/shell.html
Shellsort is a simple extension of insertion sort which gains speed by allowing exchanges of elements that are far apart. The idea is to rearrange the array to give it the property that every hth element (starting anywhere) yields a sorted array. Such an array is said to be h-sorted.
By h-sorting for some large values of h, we can move elements in the array long distances and thus make it easier to h-sort for smaller values of h. Using such a procedure for any sequence of values h which ends in 1 will produce a sorted array.
Adapted from Jason Harrison's ShellSortAlgorithm.
- Version:
- 1.0, 23 Jun 1995, 1.1, 12 Apr 2000 -- fixed java.lang.ArrayIndexOutOfBoundsException Joel Berry <jmbshifty@yahoo.com> found this bug
- Author:
- Jason Harrison@cs.ubc.ca
-
Method Summary
Modifier and TypeMethodDescriptionprotected static <T> intcompare(List<T> list, int i, int j, Comparator<? super T> comparator, SortStatistics stats) protected static <T> intcompare(T[] array, int i, int j, Comparator<? super T> comparator, SortStatistics stats) protected static <T> intcompare(T o1, T o2, Comparator<? super T> comparator, SortStatistics stats) protected static <T> Tget(List<T> list, int i, SortStatistics stats) protected static <T> Tget(T[] array, int i, SortStatistics stats) static ShellSortbooleanisStable()Checks if this is a stable sort.protected static <T> voidset(List<T> list, int i, T o, SortStatistics stats) protected static <T> voidset(T[] array, int i, T o, SortStatistics stats) <T extends E>
void<T extends E>
voidsort(List<T> list, SortStatistics stats) <T extends E>
voidsort(List<T> list, Comparator<? super T> comparator) <T> voidsort(List<T> list, Comparator<? super T> comparator, SortStatistics stats) <T extends E>
voidsort(T[] array) <T extends E>
voidsort(T[] array, SortStatistics stats) <T extends E>
voidsort(T[] array, Comparator<? super T> comparator) <T> voidsort(T[] array, Comparator<? super T> comparator, SortStatistics stats) protected static <T> voidswap(List<T> list, int i, int j, SortStatistics stats) protected static <T> voidswap(T[] array, int i, int j, SortStatistics stats)
-
Method Details
-
getInstance
-
isStable
public boolean isStable()Description copied from interface:SortAlgorithmChecks if this is a stable sort. A stable sort will keep elements with equal values in their same relative order. -
sort
- Specified by:
sortin interfaceComparisonSortAlgorithm<Object>
-
sort
- Specified by:
sortin interfaceComparisonSortAlgorithm<Object>
-
sort
- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
public <T extends E> void sort(T[] array) - Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
- Specified by:
sortin interfaceComparisonSortAlgorithm<E>
-
sort
- Specified by:
sortin interfaceComparisonSortAlgorithm<E>
-
compare
protected static <T> int compare(List<T> list, int i, int j, Comparator<? super T> comparator, SortStatistics stats) -
compare
protected static <T> int compare(T[] array, int i, int j, Comparator<? super T> comparator, SortStatistics stats) -
compare
protected static <T> int compare(T o1, T o2, Comparator<? super T> comparator, SortStatistics stats) -
get
-
get
-
set
-
set
-
swap
-
swap
-