Fixed checkstyle and docs (#2035)
* Update bubble sort algorithm * fixed checkstyle * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
486ebc2635
commit
23c12f7141
2
.github/workflows/checkstyle.yml
vendored
2
.github/workflows/checkstyle.yml
vendored
@ -1,6 +1,6 @@
|
|||||||
name: Code Formatter
|
name: Code Formatter
|
||||||
|
|
||||||
on: [push]
|
on: [push, pull_request]
|
||||||
jobs:
|
jobs:
|
||||||
format:
|
format:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -8,10 +8,13 @@ import static Sorts.SortUtils.*;
|
|||||||
* @see SortAlgorithm
|
* @see SortAlgorithm
|
||||||
*/
|
*/
|
||||||
class BubbleSort implements SortAlgorithm {
|
class BubbleSort implements SortAlgorithm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method implements the Generic Bubble Sort
|
* Implements generic bubble sort algorithm.
|
||||||
*
|
*
|
||||||
* @param array The array to be sorted Sorts the array in ascending order
|
* @param array the array to be sorted.
|
||||||
|
* @param <T> the type of elements in the array.
|
||||||
|
* @return the sorted array.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T extends Comparable<T>> T[] sort(T[] array) {
|
public <T extends Comparable<T>> T[] sort(T[] array) {
|
||||||
@ -30,20 +33,23 @@ class BubbleSort implements SortAlgorithm {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver Program
|
/** Driver Code */
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// Integer Input
|
|
||||||
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
|
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
|
||||||
BubbleSort bubbleSort = new BubbleSort();
|
BubbleSort bubbleSort = new BubbleSort();
|
||||||
bubbleSort.sort(integers);
|
bubbleSort.sort(integers);
|
||||||
|
|
||||||
// Output => 1, 4, 6, 9, 12, 23, 54, 78, 231
|
for (int i = 0; i < integers.length - 1; ++i) {
|
||||||
print(integers);
|
assert integers[i] <= integers[i + 1];
|
||||||
|
}
|
||||||
|
print(integers); /* output: [1, 4, 6, 9, 12, 23, 54, 78, 231] */
|
||||||
|
|
||||||
// String Input
|
|
||||||
String[] strings = {"c", "a", "e", "b", "d"};
|
String[] strings = {"c", "a", "e", "b", "d"};
|
||||||
// Output => a, b, c, d, e
|
bubbleSort.sort(strings);
|
||||||
print(bubbleSort.sort(strings));
|
for (int i = 0; i < strings.length - 1; i++) {
|
||||||
|
assert strings[i].compareTo(strings[i + 1]) <= 0;
|
||||||
|
}
|
||||||
|
print(bubbleSort.sort(strings)); /* output: [a, b, c, d, e] */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user