Skip to content

Commit 3551433

Browse files
authored
Merge pull request TheAlgorithms#710 from AnkitAtBrillio/local
Adding interface for sorting to use polymorphism features.
2 parents 5227629 + ed53bd0 commit 3551433

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/com/sorts/BubbleSort.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package src.main.java.com.sorts;
22

3-
public class BubbleSort {
3+
import src.main.java.com.types.Sort;
4+
5+
public class BubbleSort<T> implements Sort<T> {
46
/**
57
* This method implements the Generic Bubble Sort
68
*
79
* @param array The array to be sorted
810
* Sorts the array in increasing order
911
**/
12+
13+
@Override
1014
public <T extends Comparable<T>> T[] sort(T[] array) {
1115
int last = array.length;
1216
//Sorting

src/main/java/com/types/Sort.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package src.main.java.com.types;
2+
3+
@FunctionalInterface
4+
public interface Sort<T> {
5+
6+
public <T extends Comparable<T>> T[] sort(T[] array);
7+
}

0 commit comments

Comments
 (0)