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

Commitad5ef45

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Fixed BubbleSort Docs (TheAlgorithms#2034)
* Update shell sort documentation (TheAlgorithms#2033)* Update bubble sort algorithm* fixed checkstyle* Formatted with Google Java FormatterCo-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent39fb013 commitad5ef45

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

‎.github/workflows/checkstyle.yml‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
* @see SortAlgorithm
99
*/
1010
classBubbleSortimplementsSortAlgorithm {
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 <TextendsComparable<T>>T[]sort(T[]array) {
@@ -30,20 +33,23 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
3033
returnarray;
3134
}
3235

33-
// DriverProgram
36+
/** DriverCode */
3437
publicstaticvoidmain(String[]args) {
3538

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

41-
// Output => 1, 4, 6, 9, 12, 23, 54, 78, 231
42-
print(integers);
43+
for (inti =0;i <integers.length -1; ++i) {
44+
assertintegers[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 (inti =0;i <strings.length -1;i++) {
51+
assertstrings[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)

[8]ページ先頭

©2009-2025 Movatter.jp