Initial commit
This commit is contained in:
18
src/cl/cromer/estructuras/code/arrayOrdenado/eliminar
Normal file
18
src/cl/cromer/estructuras/code/arrayOrdenado/eliminar
Normal file
@@ -0,0 +1,18 @@
|
||||
public boolean eliminar(int valor) {
|
||||
boolean borrado = false;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] != 0 && array[i] == valor) {
|
||||
// Eliminar el valor
|
||||
array[i] = 0;
|
||||
borrado=true;
|
||||
for (int j = i; j < array.length; j++) {
|
||||
if (j != array.length - 1) {
|
||||
// Correr la array hacia arriba
|
||||
array[j] = array[j + 1];
|
||||
}
|
||||
}
|
||||
array[array.length-1] = 0;
|
||||
}
|
||||
}
|
||||
return borrado;
|
||||
}
|
Reference in New Issue
Block a user