Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15d0f56

Browse files
authored
Merge pull requestTheAlgorithms#2 from TheAlgorithms/Development
merging thealgorithms/java to ali4j/java dev branch
2 parents45fee18 +5ec13c6 commit15d0f56

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
importcom.types.Sort;
44

5-
publicclassBubbleSort<T>implementsSort<T> {
5+
publicclassBubbleSort<TextendsComparable<T>>implementsSort<T> {
66
/**
77
* This method implements the Generic Bubble Sort
88
*
@@ -11,7 +11,7 @@ public class BubbleSort<T> implements Sort<T> {
1111
**/
1212

1313
@Override
14-
public<TextendsComparable<T>>T[]sort(T[]array) {
14+
publicT[]sort(T[]array) {
1515
intlast =array.length;
1616
//Sorting
1717
booleanswap;

‎src/main/java/com/types/DataStructure.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
importjava.util.Iterator;
44

55
/**
6-
* This interface is to definebacis functionality expected out of any implementation class
6+
* This interface is to definebasic functionality expected out of any implementation class
77
* Since this is a data structure it should have the flexibility to contain any kind of object hence it has been made generic
88
* Any implementation class need not to be thread safe or it could be depending on the implementation class how does it want to behave.
99
*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
packagecom.types;
22

33
@FunctionalInterface
4-
publicinterfaceSort<T> {
4+
publicinterfaceSort<TextendsComparable<T>> {
55

6-
<TextendsComparable<T>>T[]sort(T[]array);
6+
T[]sort(T[]array);
77
}

‎src/test/java/com/sorts/BubbleSortTest.java‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@
66
classBubbleSortTest {
77

88
@Test
9-
voidbubbleSortTest() {
10-
BubbleSortbubbleSort =newBubbleSort();
9+
voidbubbleSortTestIntegers() {
10+
BubbleSort<Integer>bubbleSort =newBubbleSort<>();
1111

12-
Integer[]unsortedInt =newInteger[]{0,5,9,2,1,3,4,8,6,7};
13-
Integer[]sortedInt =newInteger[]{0,1,2,3,4,5,6,7,8,9};
12+
Integer[]unsortedInt = {0,5,9,2,1,3,4,8,6,7};
13+
Integer[]sortedInt = {0,1,2,3,4,5,6,7,8,9};
1414
Assertions.assertArrayEquals(sortedInt,bubbleSort.sort(unsortedInt));
1515

16-
Character[]unsortedChar =newCharacter[]{'f','h','c','a','b','d','g','e'};
17-
Character[]sortedChar =newCharacter[]{'a','b','c','d','e','f','g','h'};
16+
}
17+
18+
@Test
19+
voidbubbleSortTestCharacters() {
20+
BubbleSort<Character>bubbleSort =newBubbleSort<>();
21+
22+
Character[]unsortedChar = {'f','h','c','a','b','d','g','e'};
23+
Character[]sortedChar = {'a','b','c','d','e','f','g','h'};
1824
Assertions.assertArrayEquals(sortedChar,bubbleSort.sort(unsortedChar));
1925

2026
}
2127

28+
@Test
29+
voidbubbleSortTestStrings() {
30+
BubbleSort<String>bubbleSort =newBubbleSort<>();
31+
32+
String[]unsortedChar = {"abc","adc","bcd","abb","abc","acb"};
33+
String[]sortedChar = {"abb","abc","abc","acb","adc","bcd"};
34+
Assertions.assertArrayEquals(sortedChar,bubbleSort.sort(unsortedChar));
35+
36+
}
2237
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp