Arreglos Bidimensionales Arreglos Multidimensionales.

Post on 02-Feb-2016

378 views 11 download

Transcript of Arreglos Bidimensionales Arreglos Multidimensionales.

Arreglos Bidimensionales

Arreglos Multidimensionales

1714201811

69578

910151210

INGRESOS MENSUALES POR VENTAS

MI AGENDA DE AMIGOS

77578281CentroMaribel

77280666Villa FátimaAgustín

70234556Villa FátimaJorge

Un arreglo bidimensional es un conjunto de datos homogéneo , finito y ordenado, donde se hace referencia a cada elemento por medio de dos índices.

El primero se utiliza para indicar el renglón o fila y el segundo para indicar la columna.

También puede definirse como un vector de vectores.

M[0][0]

M[0][1]

M[0][2]

... M[0][m]

M[1][0]

M[1][1]

M[1][2]

... M[1][m]

M[2][0]

M[2][1]

M[2][2]

... M[2][m]

M[n][0]

M[n][1]

M[n][2]

... M[n][m]

0 1 2 ..... m

0

1

2

:

n

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

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

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

M[3][0] M[3][1] M[3][2]

M[0][0]=3

M[0][1]=6

M[0][2]=-1

M[1][0]=5

M[1][1]=2

M[1][2]=11

M[2][0]=9

M[2][1]=1

M[2][2]=4

M[3][0]=21

M[3][1]=7

M[3][2]=8

TIPO TAMAÑO RANGO(Valores numéricos de )

byte 8 bits –128 a 127

short 16 bits –32.768 a 32.767

int 32 bits –2.147.483.648 a 2.147.483.647

long 64 bits sin límite.

float 32 bits hasta 38 cifras

double 64 bits hasta 308 cifras

char 16 bits Valores alfanuméricos

String Según long

para cadenas de caracteres

boolean 8 bits Solo admite TRUE o FALSE

Declaración de una matriz y Asignación en una matriz

int [ ] [ ] matriz1;

matriz1 = new int [ 2] [ 3 ];

int [ ] [ ] matriz2 = new int [ 2 ] [ 3 ];

int [ ] [ ] matriz3 = { {3, 4, 8},{1, 2, 5} };

int [ ] [ ] matriz1;equivale a escribir:

int matriz1 [ ] [ ] ;

int [ ] [ ] matriz3 = { { 3, 4, 8 }, { 1, 2, 5 } };

equivale a escribir

int matriz3 [ ] [ ] = { { 3, 4, 8 }, { 1, 2, 5 } };

Operaciones con matrices

 num = a[2][1] + a[3][1] + 2;

dando como resultado num = 2 + 57 + 2 = 61.

a[0] [2]= (int) (Math.pow(a[2] [1], 2)) ;

dando a[0] [2]= 4.

a[0] [2]= a[0] [0] + a[1] [0] + a[2] [0];

dando a[0] [2]= -1 + 8 + 0 = 7.

a[0] [2] = a[1] [0] / a[0] [0];

dando a[0] [2] = -8. Es importante recalcar que en este caso ni a[1] [0], ni a[0] [0] alteran su contenido.

USO DE LA VARIABLE lengthDevuelve un entero que nos permite conocer la cantidad de elementos de un arreglo

1714201811

69578

9101512100

1

2

0 1 2 3 4

int num_fil;

Int num_col;

num_fil = D.length ;

num_col = D[0].length;

51

7142

1

8430

292

int a [ ] [ ] = { {0, 3, 4, 8} , {1, 5} , {2, 9, 2} , {1} , {2, 4, 1, 7} } ;int num_fil;

Int num_col;

num_fil = D.length ;

num_col0 = D[0].length;

num_col1 = D[1].length;

num_col2 = D[2].length;

num_col3 = D[3].length;

num_col4 = D[4].length;

51

7142

1

8430

292

class FunMatrices

{

metodoX ( tipo_de_mat Matriz [ ] [ ] )

{.........}

public static void main (String args[])

{ FunMatrices A= new FunMatrices();

tipo_de_mat M [ ] [ ] = new tipo_de_mat [ 4 ][4 ];

A. metodoX ( M ) ;

}

}

.............

El numero de dimensiones depende del lenguaje elegido.

Los vectores y matrices solo son casos especiales de los arreglos multidimensionales.

Por ejemplo un arreglo de tres dimensiones.

0

1

2

0 1

21

0

M(0,0,0)

M(0,1,0)

M(1,0,0)

M(1,1,0)

M(2,0,0)

M(2,1,0)

M(0,0,2)

M(0,1,2)

M(1,0,2)

M(1,1,2)

M(2,0,2)

M(2,1,2)M(0,0,1)

M(0,1,1)

M(1,0,1)

M(1,1,1)

M(2,0,1)

M(2,1,1)

int ArregloMultiDimen [ ] [ ] [ ] = new int int [ 2 ] [ 4 ] [ 5 ] ;

Gracias por su atención