Sort algos: Bubblesort

This commit is contained in:
2022-07-28 15:57:45 +02:00
parent dd16a9f8ef
commit 6661371361

View File

@@ -0,0 +1,34 @@
package com.rkcsd.apps.demo;
import java.util.Arrays;
public class BubbleSort {
static int[] arr = {24, -7, -123456, -25, -64, 555, 3234};
public static void main(String[] args) {
System.out.println(Arrays.toString(BubbleSort.sort(arr)));
}
public static int[] sort(int[] a){
int tmp;
for (int i = a.length - 1; i >= 0; i--) {
for (int j = 0; j <= i - 1; j++) {
if (a[j] > a[j + 1]) {
tmp = a[j];
a[j] = a[j + 1];
a[j + 1] = tmp;
}
}
}
return a;
}
}