mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Fixed wrong order in BubbleSort, corrected spelling mistakes
This commit is contained in:
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user