Skip to content

Instantly share code, notes, and snippets.

@EmmaG2
Last active July 6, 2022 00:13
Show Gist options
  • Save EmmaG2/611e311b10b2f8f02008648c3c0f81b9 to your computer and use it in GitHub Desktop.
Save EmmaG2/611e311b10b2f8f02008648c3c0f81b9 to your computer and use it in GitHub Desktop.
Refactorización de la función, eliminarNodo()
public boolean eliminarNodo(int elem) {
if (estaVacia()) return false;
if (inicio == fin && elem == inicio.dato) {
inicio = fin = null;
return true;
}
if (elem == inicio.dato) {
inicio = inicio.siguiente;
return true;
}
Nodo anterior, temporal;
anterior = inicio;
temporal = inicio.siguiente;
while (temporal != null && temporal.dato != elem) {
anterior = anterior.siguiente;
temporal = temporal.siguiente;
}
if (temporal == null) return false;
anterior.siguiente = temporal.siguiente;
if (temporal == fin) {
fin = anterior;
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment