
Ordenamiento Burbuja
Publicado por Juanjo (1 intervención) el 07/04/2007 19:41:54
este es un ejercicio de clase usando el metodo de ordenamiento de burbuja pero nu me sale.. aqui se los dejo y si pueden publican el error q eh cometido para poder corregirlo...
de ante mano gracias a todos por el apoyo
de ante mano gracias a todos por el apoyo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*utilizacion del Metodo de ordenacion "burbuja"y el ingreso debe ser por ventanas */
import java.io.*;
class BuscaBurbuja
{
public static void main(String arg[]) throws IOException
{
/*creacion del objeto para leer por teclado*/
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
/*ingreso del tamaño de arreglos*/
System.out.print("\n Ingrese Numero de Datos a Ingresar : ");
int tam = Integer.parseInt(in.readLine());
/*creacion del arreglo*/
int arr[] = new int[tam];
System.out.println();
/*lectura del arreglo*/
int j = 0;
for (int i = 0 ; i < arr.length;i++)
{
j+=1;
System.out.print("Elemento " + j + " : ");
arr[i] = Integer.parseInt(in.readLine());
}
burbuja(arr);
}
static void burbuja(int arreglo[])
{
for(int i = 0; i < arreglo.length - 1; i++)
{
for(int j = 0; j < arreglo.length - 1; i++)
{if (arreglo[j] < arreglo[j + 1])
{
int tmp = arreglo[j+1];
arreglo[j+1] = arreglo[j];
arreglo[j] = tmp;
}
}
}
String Mostrar = " ";
for(int i = 0;i < arreglo.length; i++)
Mostrar = Mostrar + ", " + i;
}
}
Valora esta pregunta


0