ESTRUCTURA DE DATOS ALEXIS ROJAS
Click here to load reader
Transcript of ESTRUCTURA DE DATOS ALEXIS ROJAS
![Page 1: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/1.jpg)
UNIVERSIDAD POLITECNICA DE TECAMAC
ROJAS CAMACHO ALEXIS MARIO IVAN
14150630054
2416 IS
ESTRUCTURA DE DATOS
DOMINGUEZ ESCALONA RENE
RECUPERACION
![Page 2: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/2.jpg)
Carretes
(Algoritmo)
1.-introducir el número de carretes
2.-el valor del carácter entre (2 y 200)
3.-introducir precio inicial
4.-introducir precio final
5.-calcular salida
6.-salida
PSEUDOCODIGO
Entrada de datos
public static void main(String[] args) {
Scanner lector = new Scanner(System.in);
int n,salida=0;
String cad;
Int [] pinicial,pfinal;
Proceso de datos
public static void main(String[] args) {
Scanner lector = new Scanner(System.in);
int n,salida=0;
String cad;
int[] pinicial,pfinal;
System.out.println("Introduce el numero de carretes (entre 2 y 200)");
do{
cad=lector.nextLine();
n=Integer.parseInt(cad);
}
while(n<2 || n>200);
pinicial= new int[n]; pfinal= new int[n];
System.out.println("Introduce el precio inicial");
do{ cad=lector.nextLine(); }
while(cad.length()!=n);
for(int i=0; i<n;i++) pinicial[i]=cad.charAt(i)-48;
System.out.println("Introduce el precio final");
do{ cad=lector.nextLine(); }while(cad.length()!=n);
do{ cad=lector.nextLine(); }while(cad.length()!=n);
SALIDA DE DATOS
![Page 3: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/3.jpg)
for(int i=0; i<n;i++){
int dif1,dif2,dif3,min;
dif1=Math.abs(pfinal[i]+10-pinicial[i]);
dif2=Math.abs(pfinal[i]-pinicial[i]);
dif3=Math.abs(pinicial[i]+10-pfinal[i]);
min=Math.min(Math.min(dif1, dif2),dif3);
salida+=min;
System.out.println("pfinal["+i+"]="+pfinal[i]+" pinicial["+i+"]="+pinicial[i]+" dif1="+salida+" dif2="+dif2+" dif3="+dif3+" min="+min);
}
System.out.println("salida="+salida);
}
DIAGRAMA DE FLUJO
INICIO
Introducir N entrada
h2 N<2
n>200
No
Si
Introducir N salida
N<2
N>200
No
Calcular la salida
salida
![Page 4: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/4.jpg)
Prueba de escritorio
MATRIZ TRANSPUESTA
ALGORITMO
-introducir [i],[ j]
-leer N (hasta- desde+1)+desde)
-procesos de cálculo de la matriz
-imversion de matrizT
-imprimir matriz, matrizT
SEUDOCÓDIGO
Entrada de datos
int i, j; for (i=0; i<fila; i++) {
for (j=0; j<columna; j++)
{ System .out.print(matriz[i][j]+"\t");
}
System .out.println(" ");
}
System.out.println();
}
![Page 5: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/5.jpg)
Proceso de datos
matriz
public static void main(String[] args) {
int i,j,fil,colum;
fil = ((int)(Math.random()*(10-2+1)+2));
//(int)(Math.random()*(HASTA-DESDE+1)+DESDE);
colum = ((int)(Math.random()*(10-2+1)+2));
int [] [] matriz = new int [fil][colum];
int [] [] matriz_T = new int [colum][fil];
System.out.println("La matriz es: ");
Random num = new Random();
for ( i = 0; i < fil; i++) {
for (j = 0; j < colum; j++) {
matriz [i][j] = matriz [i][j]=((int)(Math.random()*(100-2+1)+2)); }
}
matrizT
System.out.println("La transpuesta de la matriz es: ");
for(j=0;j<colum;j++) {
for (i=0;i<fil;i++) {
matriz_T[j][i]=matriz[i][j];
}
}
SALIDA DE DATOS
matriz
imprimir (matriz,fil,colum);
matrizT imprimir (matriz_T,colum,fil); }
prueba de escritorio
![Page 6: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/6.jpg)
NÚMEROS NO FIBONACCI
ALGORITMO
-fibo1, fibo2
-introducir n<=1
-proceso de termino numero Fibonacci
-imprimir términos
Seudocódigo
Entrada de datos
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
int a,fibo1,fibo2,i;
Proceso de datos
do {
System.out.print("introduce un numero mayor a 1 ");
a=sc.nextInt();
}
while (a<=1);
System.out.println("los primeros terminos son: ");
fibo1=4;
fibo2=6;
Salida de datos
System.out.print(fibo1+" ");
for (fibo2=6; fibo2<=a; fibo2++) {
System.out.print(fibo2+" ")
; fibo1= fibo1+fibo2;
fibo2= fibo2+fibo1;
}
System.out.println();
}
}
![Page 7: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/7.jpg)
Diagrama de flojo
Inicio
Fibo1=n, Fibo=n.
N<=1
Fibo1=4;
Fibo2=6;
Fibo1=fibo1+fibo2;
Fibo2=fibo2+fibo1;
Fin
no
Si
![Page 8: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/8.jpg)
Prueba de escritorio
SI TE DA
Algoritmo
-introducir valor de n1, n2.
-suma de n1+n2 con condición
-imprimir primera línea y segunda línea separadas
SEUDOCODIGO
Entrada de proceso
public static void main(String[] args) {
Scanner in;
in = new Scanner(System.in);
boolean iguales = false;
int n1= in.nextInt();
int aux1= n1;
int n2= in.nextInt();
int aux2=n2;
int contador =0;
![Page 9: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/9.jpg)
proceso de datos
System.out.print(n1+"+n2+");
while (iguales == false){
int temp =n1+n2;
if (temp>10){
temp-=10;
}
System.out.print(temp+" ");
n1=n2; n2=temp;
contador++;
if (n1== aux1&&n2==aux2){
iguales=true;
}
}
Salida de datos
System.out.println("");
System.out.println(contador+"veces");
}
}
![Page 10: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/10.jpg)
Diagrama de flojo
Iguales==false
Imprimir linea1,linea2.
inicio
N1,n2
N1+n2, Temp-=10
N1=n2
fin
![Page 11: ESTRUCTURA DE DATOS ALEXIS ROJAS](https://reader038.fdocumento.com/reader038/viewer/2022100800/58edb0121a28abf77e8b45c9/html5/thumbnails/11.jpg)
Prueba de escritorio