Skip to content

Instantly share code, notes, and snippets.

@Hikhuj
Last active February 16, 2019 02:46
Show Gist options
  • Save Hikhuj/54a103a4c9698e12d1bb45275282ff78 to your computer and use it in GitHub Desktop.
Save Hikhuj/54a103a4c9698e12d1bb45275282ff78 to your computer and use it in GitHub Desktop.
//Practica 2: public void elimina (int year)
public void elimina(int anio){
Nodo aux = cabeza;
// Si ELIMINAR primer dato
if(anio == aux.getDato().getAnios()){
cabeza = aux.getNext();
aux = null;
}
}
//Practica 2.1: Elimina ultimo dato
public void elimina(int anio) {
Nodo aux = cabeza;
// Si ELIMINA ultimo dato
if(anio == aux.getNext().getDato().getAnios() && aux.getNext().getNext() == null){
cabeza.setNext(null);
}
}
// Practica 2.3: Elimina dato del medio
public void elimina(int anio) {
Nodo aux = cabeza;
// Si ELIMINA ultimo dato
while(aux.getNext() != null) {
if(anio == aux.getNext().getDato().getAnios() && aux.getNext().getNext() != null){
Nodo tmp = aux.getNext().getNext();
aux.setNext(tmp);
}else{
aux = aux.getNext();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment