¿Por referencia / por valor?.
Publicado por David (1 intervención) el 22/02/2012 02:00:36
Hola, tengo una duda,
Si yo tengo este código
[...]
static long tiempo = 0;
public static void main(String[] args)
{
int test2 [] = {435,544,33,22,4,23,54,12323,5,3,0,121,4,65};
ordenar_array_Burbuja(test);
}
public static void ordenar_array_Burbuja(int array_a_ordenar[]) // Función que devuelte un array ordenado
{
mostrar_array(array_a_ordenar);
tiempo = System.currentTimeMillis();
int n = array_a_ordenar.length;
for (int pass=1; pass < n; pass++) { // count how many times
// This next loop becomes shorter and shorter
for (int i=0; i < n-pass; i++) {
if (array_a_ordenar[i] > array_a_ordenar[i+1]) {
// exchange elements
int temp = array_a_ordenar[i]; array_a_ordenar[i] = array_a_ordenar[i+1]; array_a_ordenar[i+1] = temp;
}
}
}
long total = 0;
total = System.currentTimeMillis()-tiempo;
System.out.println("He tardado "+ total +" en terminar");
mostrar_array(array_a_ordenar);
}
[...]
Si luego muestro "test2", no tiene el valor inicial (435,544,33,22,4,23,54,12323,5,3,0,121,4,65), esta ordenado, ¿porqué se modifica el valor de test2?. ¿este es así siempre?.
Si yo tengo este código
[...]
static long tiempo = 0;
public static void main(String[] args)
{
int test2 [] = {435,544,33,22,4,23,54,12323,5,3,0,121,4,65};
ordenar_array_Burbuja(test);
}
public static void ordenar_array_Burbuja(int array_a_ordenar[]) // Función que devuelte un array ordenado
{
mostrar_array(array_a_ordenar);
tiempo = System.currentTimeMillis();
int n = array_a_ordenar.length;
for (int pass=1; pass < n; pass++) { // count how many times
// This next loop becomes shorter and shorter
for (int i=0; i < n-pass; i++) {
if (array_a_ordenar[i] > array_a_ordenar[i+1]) {
// exchange elements
int temp = array_a_ordenar[i]; array_a_ordenar[i] = array_a_ordenar[i+1]; array_a_ordenar[i+1] = temp;
}
}
}
long total = 0;
total = System.currentTimeMillis()-tiempo;
System.out.println("He tardado "+ total +" en terminar");
mostrar_array(array_a_ordenar);
}
[...]
Si luego muestro "test2", no tiene el valor inicial (435,544,33,22,4,23,54,12323,5,3,0,121,4,65), esta ordenado, ¿porqué se modifica el valor de test2?. ¿este es así siempre?.
Valora esta pregunta


0