35 lines
639 B
Java
35 lines
639 B
Java
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;
|
|
}
|
|
}
|
|
|