Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/main/java/algorithm/BubbleSortSnippet.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@
* SOFTWARE.
*/

package algorithm;
package algorithm;

/**
* BubbleSortSnippet.
*/
public class BubbleSortSnippet {

/**
* Sort an array with bubbleSort algorithm.
*
* @param arr array to sort
*/
public static void bubbleSort(int[] arr) {
var lastIndex = arr.length - 1;

for (var j = 0; j < lastIndex; j++) {
for (var i = 0; i < lastIndex - j; i++) {
if (arr[i] > arr[i + 1]) {
var tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
}
}
}
}
}
/**
* BubbleSortSnippet.
*/
public class BubbleSortSnippet {
/**
* Sort an array with bubbleSort algorithm.
*
* @param arr array to sort
*/
public static void bubbleSort(int[] arr) {
var lastIndex = arr.length - 1;
for (var j = 0; j < lastIndex; j++) {
for (var i = 0; i < lastIndex - j; i++) {
if (arr[i] > arr[i + 1]) {
var tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
}
}
}
}
}