Sie sind auf Seite 1von 10

Grupo 03 Laboratorio 4 Algoritmia y Programacin Leoviviana Moreno.

Ana Sofia Hurtado Maira Alejandra Borrero Jos Alejandro Giraldo

1225792 1224825 1227389

2 ordenamiento por conteo (uso de arreglos y matrices).

Entradas: datos,crearmatriz, contarvalores, desplegarmatriz. Salidas: valores contados, matriz desplegada, matrizcreada. Proceso: 1. utilizar mtodo para desplegar men. 2. utilizar mtodo para leer datos. 3. utilizar mtodo para obtener valores al azar. 4. utilizar mtodo para crear matriz. 5.utilizar mtodo para contar valores. 6.utilizar mtodo para desplegar matriz. PSEUDOCDIGO:
matriiz, f, c, k, arreglo; entero menu() entero opcion entero leer (opcion) retornar opcion. Void leer datos() leer (f) leer (c) leer (k) valoresalazar() enteros valor entero leer (valor) valor: (math.random()* (k+1)) retornar valor. Void crearmatriz() mensaje= texto matriz= new entero [f][c] desde (entero i=0; i<f; i++)

desde (entero j=0; j<c; j++) matriz[i][j]= valoresazar()

mensaje=mensaje+matriz[i][j] fin desde mensaje= mensaje fin desde imprimir (mensaje) void contarvalores() texto conteo=ocurrencia/conteo: texto valor=valor/posixcion: arreglo= new entero [k+1] desde (entero i=0; i<f; i++) desde (entero j=0; j<c; j++) arreglo(matriz[i][j])++ fin desde fin desde desde (entero h=0; h<arreglo.length; h++) conteo= conteo + arreglo [h] valor= valor + h imprimir (conteo + valor) void desplegarmatriz() texto mensaje = limite=0 entero orden entero leer (orden) si (orden==1) desde (entero i=0; i<=k;i++) desde (entero j=0; j<arreglo [i]; j++) mensaje= mensaje + i limite ++ si (limite==f) mensaje==mensaje limite=0 fin si fin desde fin desde sino si (orden==2) desde (entero i=k; i>=0; i--) desde (entero j=0; J<arreglo[]; j++) mensaje= mensaje +i limite ++

si (limite==C) mensaje=mensaje limite=0 fin si fin desde fin desde fin si fin si imprimir (mensaje) fin INICIO ordenamiento conteo objeto= new ordenamientoconteo () opcion entero haga opcin=objeto.menu() si (opcin==1) leer dato() sino si(opcin==2) crearmatriz() sino si(opcion==3) contarvalores() sino si(opcion==4) desplegarmatriz() mientras(opcion!=5) fin si fin si fin si fin si fin
3, prueba de escritorio Matriz[][] Menu opcion 1 LeerDatos f c k f c k arreglo[]

2 2 1 ValoresAzar valor 01 2 CrearMatriz mensaje 0 [0] [0][0] matriz[0][0]= 0 matriz[0][1]= 0 1 [0][0] [0][0] [0][1] [0] matriz[1][0]= 0 matriz[1][1]= 0 0 1 2 2 3 ContarValores conteo valor arreglo[matriz[i][j] i 0 Arreglo[0]= 1 Arreglo[0]= 2 1 Arreglo[0]= 3 Arreglo[1]= 1 2 ocurrencia/conteo: valor/posicion: [3] [0] ocurrencia/conteo: valor/posicion: [3][1] [0][1] 0 1 0 1 2 0 1 2 j h ocurrencia/conteo: valor/posicion: 0 1 2 matriz[i][j] i j

2 4 DesplegarMatriz mensaje limite orden 0 1 0 [0] [0][0] [0][0] [0][0] [0] 1 2 0 1 2 3 1 [0][0] [0][1] [0][0] [0][1] 2 0 0 0 1 i j f 2 ck 21

1 2 2 1 [1] 1 0 [1][0] [1][0] [1][0] [0] [1][0] [0][0] [1][0] [0][0] 2 0 1 2 0 1 2 0 0 1

3 1 5. evidencia de ejecucion de informe public static int Menu(){ int opcion; opcion=Integer.parseInt(JOptionPane.showInputDialog("--- Ordenamiento por Conteo---\n"+"Men\n"+"1. Leer Datos\n"+"2. Crear Matriz\n"+"3. Contar Valores\n"+"4. Desplegar Matriz")); return opcion;

public static void LeerDatos(){ f=Integer.parseInt(JOptionPane.showInputDialog("Digite el numero de filas de la matriz")); c=Integer.parseInt(JOptionPane.showInputDialog("Digite el numero de columnas de la matriz")); k=Integer.parseInt(JOptionPane.showInputDialog("Digite el rango hasta el cual se van a ubicar los valores en la matriz")); } public static int ValoresAzar(){ int valor; valor= (int) (Math.random()*(k+1)); return valor;

public static void CrearMatriz(){ String mensaje=""; matriz= new int [f][c]; for(int i=0; i<f; i++){ for(int j=0; j<c; j++){ matriz[i][j]= ValoresAzar(); mensaje=mensaje+"["+matriz[i][j]+"]\t"; } mensaje=mensaje+"\n"; } JOptionPane.showMessageDialog(null, "La matriz es: \n"+mensaje); }

public static void ContarValores(){ String conteo="ocurrencia/conteo: "; String valor="valor/posicion: "; arreglo=new int [k+1]; for(int i=0; i<f; i++){ for(int j=0; j<c; j++){ arreglo[matriz[i][j]]++; } } for(int h=0; h<arreglo.length; h++){ conteo=conteo+"["+arreglo[h]+"]\t"; valor= valor+"["+h+"]"; } JOptionPane.showMessageDialog(null, "El conteo es: \n"+conteo+"\n"+valor); }

public static void DesplegarMatriz(){ String mensaje=""; int limite=0; int orden; orden=Integer.parseInt(JOptionPane.showInputDialog("Digite el orden en el cual se ubicaran los valores en la matriz\n"+"1. Ascendente\n"+"2.Descendente")); if(orden==1){ for(int i=0;i<=k;i++){ for(int j=0;j<arreglo[i];j++){ mensaje = mensaje +"["+i+"]"; limite++;

if(limite == f){ mensaje = mensaje +"\n"; limite=0; } } } JOptionPane.showMessageDialog(null, mensaje); }

}else if(orden==2){ for(int i=k;i>=0;i--){ for(int j=0;j<arreglo[i];j++){ mensaje = mensaje +"["+i+"]"; limite++; if(limite == c){ mensaje = mensaje +"\n"; limite=0; } } } } JOptionPane.showMessageDialog(null, mensaje); }

Das könnte Ihnen auch gefallen