Fixed wrong order in BubbleSort, corrected spelling mistakes

This commit is contained in:
Igor Kvashnin
2020-06-30 22:44:38 +03:00
parent 88d65ff5bf
commit 95389bf9c6
2 changed files with 20 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ class BubbleSort implements SortAlgorithm {
* This method implements the Generic Bubble Sort
*
* @param array The array to be sorted
* Sorts the array in increasing order
* Sorts the array in ascending order
**/
@Override
@@ -21,7 +21,7 @@ class BubbleSort implements SortAlgorithm {
for (int i = 0, size = array.length; i < size - 1; ++i) {
boolean swapped = false;
for (int j = 0; j < size - 1 - i; ++j) {
if (less(array[j], array[j + 1])) {
if (greater(array[j], array[j + 1])) {
swap(array, j, j + 1);
swapped = true;
}
@@ -41,12 +41,12 @@ class BubbleSort implements SortAlgorithm {
BubbleSort bubbleSort = new BubbleSort();
bubbleSort.sort(integers);
// Output => 231, 78, 54, 23, 12, 9, 6, 4, 1
// Output => 1, 4, 6, 9, 12, 23, 54, 78, 231
print(integers);
// String Input
String[] strings = {"c", "a", "e", "b", "d"};
//Output => e, d, c, b, a
//Output => a, b, c, d, e
print(bubbleSort.sort(strings));
}