JavaAlgorithms/Sorts/SortAlgorithm.java

33 lines
816 B
Java
Raw Normal View History

2018-11-14 01:15:47 +08:00
package Sorts;
import java.util.Arrays;
import java.util.List;
/**
* The common interface of most sorting algorithms
*
* @author Podshivalov Nikita (https://github.com/nikitap492)
**/
public interface SortAlgorithm {
2018-04-12 15:14:22 +08:00
/**
* Main method arrays sorting algorithms
*
2018-04-12 15:14:22 +08:00
* @param unsorted - an array should be sorted
* @return a sorted array
*/
<T extends Comparable<T>> T[] sort(T[] unsorted);
2018-04-12 15:14:22 +08:00
/**
* Auxiliary method for algorithms what wanted to work with lists from JCF
*
2018-04-12 15:14:22 +08:00
* @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()])));
}
}