Estoy intentando invertir el orden de una matriz en Java.
¿Cuál es la forma más eficiente de hacerlo en O (n) con la menor cantidad de memoria utilizada?
No hay necesidad de responder con código, el pseudo código estará bien.
Aquí es mi proceso de pensamiento:Reverse Array Order
create a new temp array //I think this is a waste of memory,
//but I am not sure if there's a better way
grab elements from the end of the original array -decrement this variable
insert element in beginning of temp array -increment this variable
then make the original array point to the temp array? //I am not sure
//if I can do this in java; so let's say the
//original array is Object[] arr; and the temp array is
//Object[] temp. Can I do temp = arr; ?
¿Hay una manera mejor y más eficiente de hacer esto tal vez sin el uso de una matriz temporal? y, por último, suponga que no hay nulos en la matriz, por lo que todo puede funcionar. Gracias
Editar: no, esto no es tarea.
¿Es esta tarea? En caso afirmativo, etiquetado como tal. –
considere cambiar los artículos primero y último y luego los segundos y segundos últimos hasta llegar a la mitad de la lista ...solo necesitará una variable temporal y aún revisará la lista una vez? –
http://stackoverflow.com/questions/2137755/how-do-i-reverse-an-int-array-in-java –