Ordenamiento Burbuja Java
Enviado por José Enrique Escobedo • 6 de Octubre de 2018 • Tarea • 650 Palabras (3 Páginas) • 94 Visitas
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ej13;
import javax.swing.JOptionPane;
public class Burbuja extends FORM05 {
private String strTotal;
private int intTotal,i,temp;
private int[] intNumeros;
private boolean bandera;
private String[] strNumeros;
public Burbuja(){
this.bandera = true;
this.i = 0;
this.temp = 0;
this.intTotal = 0;
}
public void PEDIR_NUMEROS(){
this.strTotal = JOptionPane.showInputDialog("Cuantos numeros deseas ordenar?");
this.intTotal = Integer.parseInt(this.strTotal);
this.intNumeros = new int[this.intTotal];
this.strNumeros = new String[this.intTotal];
for(this.i=1;i<=intTotal;i++){
this.strNumeros[this.i-1] = JOptionPane.showInputDialog("Numero " +i
);
this.intNumeros[this.i-1] = Integer.parseInt(strNumeros[this.i-1]);
}
}
public void ORDEN_DESCENDENTE(){
while (this.bandera){
this.bandera = false;
for( this.i=0; this.i<this.intNumeros.length-1; this.i++){
if (this.intNumeros[this.i]<this.intNumeros[this.i+1]){
this.temp = this.intNumeros[this.i];
this.intNumeros[this.i] = this.intNumeros[this.i+1];
this.intNumeros[this.i+1] = this.temp;
this.bandera = true;
}
}
}
}
public void ORDEN_ASCENDENTE(){
while (this.bandera){
this.bandera = false;
for( this.i=0; this.i<this.intNumeros.length-1; this.i++){
if (this.intNumeros[this.i]>this.intNumeros[this.i+1]){
this.temp = this.intNumeros[this.i];
this.intNumeros[this.i] = this.intNumeros[this.i+1];
this.intNumeros[this.i+1] = this.temp;
this.bandera = true;
}
}
}
}
public void MOSTRAR_ORDENADOS(){
System.out.println("Los numeros ordenados son;\n");
for (this.i=0;this.i<this.intTotal;this.i++){
//JOptionPane.showMessageDialog(null,this.intNumeros[this.i]+" ");
System.out.print(this.intNumeros[this.i]+" ");
}
System.out.println("\n-------------------------------------------------\n");
...