public void eliminar(int posicion) { int contador = 0; if (verificarCabeza() == true) { throw new Exception("No hay ningun juego"); } else if (posicion <= 0) { throw new Exception("La posicion especificada no es valida debe ser mayor a cero"); } else if (posicion > numeroRegistros) { throw new Exception("La posicion no existe, existen actualmente: " + numeroRegistros + " Registros"); } else if (posicion == 1) { cabeza = cabeza.getSiguiente(); if (cabeza != null) { cabeza.setAnterior(null); } numeroRegistros--; } else { JuegoNodo temp = cabeza; while (temp != null) { contador++; if (contador == posicion) { if (temp.getSiguiente() != null) { temp.getSiguiente().setAnterior(temp.getAnterior()); temp.getAnterior().setSiguiente(temp.getSiguiente()); } else { temp.getAnterior().setSiguiente(null); } numeroRegistros--; break; } temp = temp.getSiguiente(); } } }
public void agregarInicio(JuegoNodo juego) { if (verificarCabeza() == true) { cabeza = juego; numeroRegistros++; } else { cabeza.setAnterior(juego); juego.setSiguiente(cabeza); cabeza = juego; numeroRegistros++; } }