From e2c5f75be7cb4a42369ddd3a4ac43314851c1a11 Mon Sep 17 00:00:00 2001 From: shellhub Date: Wed, 18 Nov 2020 09:14:40 +0800 Subject: [PATCH 1/3] Update bubble sort algorithm --- Sorts/BubbleSort.java | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Sorts/BubbleSort.java b/Sorts/BubbleSort.java index 80385d24280f..1b1d75e54101 100644 --- a/Sorts/BubbleSort.java +++ b/Sorts/BubbleSort.java @@ -8,10 +8,13 @@ * @see 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 the type of elements in the array. + * @return the sorted array. */ @Override public > T[] sort(T[] array) { @@ -30,20 +33,25 @@ public > T[] sort(T[] array) { return array; } - // Driver Program + /** + * Driver Code + */ public static void main(String[] args) { - // Integer Input Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12}; BubbleSort bubbleSort = new BubbleSort(); bubbleSort.sort(integers); - // Output => 1, 4, 6, 9, 12, 23, 54, 78, 231 - print(integers); + for (int i = 0; i < integers.length - 1; ++i) { + 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"}; - // Output => a, b, c, d, e - print(bubbleSort.sort(strings)); + 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] */ } } From f19a8ab2811decd9812e1af683d3b4fcb24fdb87 Mon Sep 17 00:00:00 2001 From: shellhub Date: Wed, 18 Nov 2020 09:17:48 +0800 Subject: [PATCH 2/3] fixed checkstyle --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 4a2e972be21c..8424300048a0 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -1,6 +1,6 @@ name: Code Formatter -on: [push] +on: [push, pull_request] jobs: format: runs-on: ubuntu-latest From 629bed27074ea53d98bf96e86c23f9f219a44751 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 18 Nov 2020 01:18:35 +0000 Subject: [PATCH 3/3] Formatted with Google Java Formatter --- Sorts/BubbleSort.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sorts/BubbleSort.java b/Sorts/BubbleSort.java index 1b1d75e54101..9ca94954d641 100644 --- a/Sorts/BubbleSort.java +++ b/Sorts/BubbleSort.java @@ -33,9 +33,7 @@ public > T[] sort(T[] array) { return array; } - /** - * Driver Code - */ + /** Driver Code */ public static void main(String[] args) { Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};