Addint type package to have interfaces to take benefit of polymorphism features
This commit is contained in:
parent
5227629d3e
commit
a023542464
@ -1,12 +1,16 @@
|
|||||||
package src.main.java.com.sorts;
|
package src.main.java.com.sorts;
|
||||||
|
|
||||||
public class BubbleSort {
|
import src.main.java.com.types.Sort;
|
||||||
|
|
||||||
|
public class BubbleSort<T> implements Sort<T> {
|
||||||
/**
|
/**
|
||||||
* This method implements the Generic Bubble Sort
|
* This method implements the Generic Bubble Sort
|
||||||
*
|
*
|
||||||
* @param array The array to be sorted
|
* @param array The array to be sorted
|
||||||
* Sorts the array in increasing order
|
* Sorts the array in increasing order
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
@Override
|
||||||
public <T extends Comparable<T>> T[] sort(T[] array) {
|
public <T extends Comparable<T>> T[] sort(T[] array) {
|
||||||
int last = array.length;
|
int last = array.length;
|
||||||
//Sorting
|
//Sorting
|
||||||
|
6
src/main/java/com/types/Sort.java
Normal file
6
src/main/java/com/types/Sort.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package src.main.java.com.types;
|
||||||
|
|
||||||
|
public interface Sort<T> {
|
||||||
|
|
||||||
|
public <T extends Comparable<T>> T[] sort(T[] array);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user