Skip to content

Commit 23c12f7

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Fixed checkstyle and docs (TheAlgorithms#2035)
* Update bubble sort algorithm * fixed checkstyle * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 486ebc2 commit 23c12f7

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

.github/workflows/checkstyle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Code Formatter
22

3-
on: [push]
3+
on: [push, pull_request]
44
jobs:
55
format:
66
runs-on: ubuntu-latest

Sorts/BubbleSort.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
* @see SortAlgorithm
99
*/
1010
class BubbleSort implements SortAlgorithm {
11+
1112
/**
12-
* This method implements the Generic Bubble Sort
13+
* Implements generic bubble sort algorithm.
1314
*
14-
* @param array The array to be sorted Sorts the array in ascending order
15+
* @param array the array to be sorted.
16+
* @param <T> the type of elements in the array.
17+
* @return the sorted array.
1518
*/
1619
@Override
1720
public <T extends Comparable<T>> T[] sort(T[] array) {
@@ -30,20 +33,23 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
3033
return array;
3134
}
3235

33-
// Driver Program
36+
/** Driver Code */
3437
public static void main(String[] args) {
3538

36-
// Integer Input
3739
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
3840
BubbleSort bubbleSort = new BubbleSort();
3941
bubbleSort.sort(integers);
4042

41-
// Output => 1, 4, 6, 9, 12, 23, 54, 78, 231
42-
print(integers);
43+
for (int i = 0; i < integers.length - 1; ++i) {
44+
assert integers[i] <= integers[i + 1];
45+
}
46+
print(integers); /* output: [1, 4, 6, 9, 12, 23, 54, 78, 231] */
4347

44-
// String Input
4548
String[] strings = {"c", "a", "e", "b", "d"};
46-
// Output => a, b, c, d, e
47-
print(bubbleSort.sort(strings));
49+
bubbleSort.sort(strings);
50+
for (int i = 0; i < strings.length - 1; i++) {
51+
assert strings[i].compareTo(strings[i + 1]) <= 0;
52+
}
53+
print(bubbleSort.sort(strings)); /* output: [a, b, c, d, e] */
4854
}
4955
}

0 commit comments

Comments
 (0)