Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/12/2010, 19:07
drackos
 
Fecha de Ingreso: diciembre-2010
Mensajes: 2
Antigüedad: 14 años, 4 meses
Puntos: 0
Sonrisa Ayuda con Array

Estoy haciendo un programa el cual tiene que tener un arreglo a este se le da el valor del tamano por medio de input y se le indica el valor de cada espacio del arreglo, para luego hacer un sort con el bubble sort y ponerlos de menor a mayor y de mayor a menor y los muestre , luego que muestre el menor
Cita:
import javax.swing.*;

public class PruebaCortaGabrielSanchezR00230241
{

public static void main( String args[] )
{
final int LONGITUD_ARREGLO;
int arreglo[];
int cont = 0;
int a,tempValue,i,j;


String strLONGITUD;

strLONGITUD = JOptionPane.showInputDialog("Entre el tamano del arreglo:");

strLONGITUD.trim();

LONGITUD_ARREGLO = Integer.parseInt(strLONGITUD);

a = LONGITUD_ARREGLO - 1;

arreglo = new int[ a ];


while (cont <= a)
{

String f;

f = JOptionPane.showInputDialog("Entre el valor del vector " + cont + ":" );

f.trim();


arreglo[cont]= Integer.parseInt(f);



cont = cont + 1;

}


//BubbleSort
for(i = 0; i <arreglo.length - 1; i++)
{

System.out.println("Pass # " + (i+1));

for (j = 0; j<arreglo.length-i-1; j++)
{

if(arreglo[ j] > arreglo[j+1])
{

JOptionPane.showMessageDialog(null,"Exchange " +arreglo[ j] + " <-> " + arreglo[ j+1]);

tempValue = arreglo[j];
arreglo[j] = arreglo[j+1];
arreglo[j+1] = tempValue;

}
}
}

for(i=0; i<arreglo.length; i++)
{
System.out.println(arreglo[i]);
}
}
}

Última edición por drackos; 01/12/2010 a las 19:09 Razón: me falto el codigo que tengo ya echo