Documente Academic
Documente Profesional
Documente Cultură
FACULTAD DE INGENIERA
Algoritmos y Estructura
de Datos II
AAREGLOS Y OBJETOS
Qu recuerdo de un arreglo?
Solucionando el problema
qu pasara si ahora
tengo que registrar el
nombre, edad y talla de
cada uno de mis
compaeros para
finalmente mostrarlos
en una tabla. Cmo lo
resolvera?
Logro Esperado
Al trmino de la sesin, el
estudiante resuelve un
problema real planteado
por el profesor, usando
arreglos, sustentando su
solucin con un diseo de
la solucin propuesta.
ARREGLOS Y OBJETOS
Trabajando juntos
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice= new Point(4,4);
p[1] = p[0];
p[2] = vertice;
http://docs.oracle.com/javase/7/docs/api/
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice = new Point(4,4);
p[1] = p[0];
p[2] = vertice;
p[0]
p[1]
p[2]
Point: (0, 0)
Point: (1, 1)
Point: (2, 2)
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice = new Point(4,4);
p[1] = p[0];
p[2] = vertice;
p[0]
p[1]
p[2]
Point: (1, 0)
Point: (1, 1)
Point: (2, 2)
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice = new Point(4,4);
p[1] = p[0];
p[2] = vertice;
p[0]
p[1]
p[2]
Point: (1, 0)
Point: (1, 2)
Point: (2, 2)
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice = new Point(4,4);
p[1] = p[0];
p[2] = vertice;
vertice
p[0]
p[1]
p[2]
Point: (4, 4)
Point: (1, 0)
Point: (1, 2)
Point: (2, 2)
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice = new Point(4,4);
p[1] = p[0];
p[2] = vertice;
vertice
p[0]
p[1]
p[2]
Point: (4, 4)
Point: (1, 0)
Point: (2, 2)
Considere
Point[] p = new Point[3];
p[0] = new Point(0, 0);
p[1] = new Point(1, 1);
p[2] = new Point(2, 2);
p[0].setX(1);
p[1].setY(p[2].getY());
Point vertice = new Point(4,4);
p[1] = p[0];
p[2] = vertice;
vertice
p[0]
p[1]
p[2]
Point: (4, 4)
Point: (1, 0)
Inicializacin explcita
Sintaxis
id Hace referencia a un array de n elementos. id[0]
tiene el valor exp0 , id[1] Tiene el valor exp1 , y ...
Inicializacin explcita
Ejemplo
String[] mascota = { canela, milusa,
jack", estrella" };
int[] uno = { 1 };
Equivale a
String[] mascota = new String[4];
mascota[0] = canela"; mascota[1] = milusa";
mascota[2] = jack";
mascota[3] = estrella";
int[] uno = new int[1];
uno[0] = 1;
Mtodo clone()
Produce una copia superficial
Point[] u = {new Point(0, 0), new
Point(1, 1)};
Point[] v = u.clone();
v[1] = new Point(4, 30);
u[1]
Point: (0, 0)
v
v[0]
v[1]
Point: (1, 1)
u[1]
Point: (0, 0)
Point: (1, 1)
v[1]
Ejemplo
Point[] w = new Point[u.length];
for (int i = 0; i < u.length; ++i) {
w[i] = u[i].clone();
}
u[1]
u[2]
Point: (0, 0)
w[0]
w[1]
Point: (2, 1)
Point: (2, 2)
Point: (2, 1)
Point: (2, 2)
w[2]
Point: (0, 0)
Solucin al problema
PREGUNTAS
Preguntas
Cmo defino una arreglo
de objetos de manera
general?
Cmo accedemos a las
propiedades de cada objeto
dentro del arreglo?
Para qu me sirve el
mtodo clone?
Cmo puedo sacar una
copia de un arreglo?
Explique sus alternativas.
cmo puedo saber si dos
arreglos son iguales?
Problema propuesto
Generar un vector de
puntos aleatorios que
pertenezcan al primer
cuadrante del eje de
coordenadas
cartesianas y encontrar
la distancia de cada
punto al centro (0,0)
determinando la mayor
distancia