ordenar una matriz de 1
x m con metodo de la burbuja en forma ascendente
package aplicaciones;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author jarol
*/
public class Aplicaciones {
public static void main(String[] args) throws IOException
{
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
int i, j, c, f,p = 0;
double a, b;
System.out.print("ingrese la cantida de Columnas
");
c = Integer.parseInt(in.readLine());
int X[][] = new int[100][100];
for (i = 1; i <= 1; i = i + 1) {
for (j = 1; j <= c; j = j + 1) {
System.out.print("Ingrese elemento de la fila "
+ 1+ " y la columna " + j);
X[i][j] = Integer.parseInt(in.readLine());
}
}
while( p <= c){
for (i = 1; i <= f; i = i + 1) {
for (j = 1; j < c; j = j + 1) {
if (X[i][j] > X[i][j + 1]) {
int aux = X[i][j];
X[i][j] = X[i][j + 1];
X[i][j + 1] = aux;
}
}
}
p =p+1;
}
//prueba
for (i = 1; i <= f; i = i + 1) {
for (j = 1; j <= c; j = j + 1) {
System.out.print("\n elemento de la fila " + i
+ " y la columna " + j + " : " + X[i][j]);
}
}
No hay comentarios:
Publicar un comentario