Last active
July 6, 2022 00:13
-
-
Save EmmaG2/611e311b10b2f8f02008648c3c0f81b9 to your computer and use it in GitHub Desktop.
Refactorización de la función, eliminarNodo()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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