public class MiBurbuja {
public static void main(String[] args) {
System.out.println("Vector1: ");
int vector[] = { 100, 3, 6, 77, 9, 90, 13, 200, 10 };
miBurbuja(vector);
mostrarVector(vector);
System.out.println("Vector ordenado: ");
System.out.println("Vector2: ");
int vector2[] = { 23, 25, 29, 30 };
miBurbuja(vector2);
mostrarVector(vector2);
}
static void mostrarVector(int vector[]) {
for (int e = 0; e < vector.length; e++) {
System.out.println(vector[e]);
}
}
static void miBurbuja(int vector[]) {
int aux = 0;
int max = vector.length;
boolean esOrdenado = true;
for (int x = 1; x < max; x++) {
if (vector[x - 1] > vector[x]) {
aux = vector[x];
vector[x] = vector[x - 1];
vector[x - 1] = aux;
esOrdenado = false;
}
if (x == max - 1) {
if (esOrdenado)
break;
x = 0;
max--;
esOrdenado = true;
}
}
}
}