2018-11-14 01:15:47 +08:00
|
|
|
package Sorts;
|
2018-04-09 17:05:41 +08:00
|
|
|
|
2018-04-09 19:04:46 +08:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-04-09 17:05:41 +08:00
|
|
|
/**
|
2019-05-09 19:32:54 +08:00
|
|
|
* The common interface of most sorting algorithms
|
2018-04-09 17:05:41 +08:00
|
|
|
*
|
|
|
|
* @author Podshivalov Nikita (https://github.com/nikitap492)
|
2020-10-24 18:23:28 +08:00
|
|
|
*/
|
2018-04-09 17:05:41 +08:00
|
|
|
public interface SortAlgorithm {
|
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/**
|
|
|
|
* Main method arrays sorting algorithms
|
|
|
|
*
|
|
|
|
* @param unsorted - an array should be sorted
|
|
|
|
* @return a sorted array
|
|
|
|
*/
|
|
|
|
<T extends Comparable<T>> T[] sort(T[] unsorted);
|
2018-04-09 19:04:46 +08:00
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/**
|
|
|
|
* Auxiliary method for algorithms what wanted to work with lists from JCF
|
|
|
|
*
|
|
|
|
* @param unsorted - a list should be sorted
|
|
|
|
* @return a sorted list
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
default <T extends Comparable<T>> List<T> sort(List<T> unsorted) {
|
|
|
|
return Arrays.asList(sort(unsorted.toArray((T[]) new Comparable[unsorted.size()])));
|
|
|
|
}
|
2018-04-09 17:05:41 +08:00
|
|
|
}
|