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 int buscarPorTitulo(string pTitulo) { int contador = 0; int result = -1; if (verificarCabeza() == true) { throw new Exception("No hay ningun juego"); } else if (pTitulo == null || pTitulo == "") { throw new Exception("El titulo no debe estar vacio"); } else { JuegoNodo temp = cabeza; while (temp != null) { contador++; if (temp.darTitulo().ToLower().Equals(pTitulo.ToLower())) { result = contador; break; } temp = temp.getSiguiente(); } if (result == -1) { throw new Exception("No se ha econtrado un juego con el titulo: " + pTitulo); } } return(result); }
public JuegoNodo buscarPorPosicion(int pos) { JuegoNodo jn = null; int contador = 0; if (verificarCabeza()) { throw new Exception("No hay ningun juego"); } else if (pos <= 0) { throw new Exception("La posicion especificada no es valida debe ser mayor a cero"); } else if (pos > numeroRegistros) { throw new Exception("La posicion no existe, existen actualmente: " + numeroRegistros + " Registros"); } else { JuegoNodo temp = cabeza; while (temp != null) { contador++; if (contador == pos) { jn = temp; break; } temp = temp.getSiguiente(); } } return(jn); }
public void recorrer() { JuegoNodo nodo = cabeza; while (nodo != null) { nodo = nodo.getSiguiente(); } }
public void ordenarPorPrecio() { if (verificarCabeza() == true) { throw new Exception("No hay elementos para ordenar"); } else { JuegoNodo puntero1 = cabeza; while (puntero1 != null) { JuegoNodo minimo = puntero1; JuegoNodo puntero2 = puntero1.getSiguiente(); while (puntero2 != null) { if (puntero2.darPrecio() < minimo.darPrecio()) { minimo = puntero2; } puntero2 = puntero2.getSiguiente(); } if (minimo != puntero1) { string tituloMinimo = minimo.darTitulo(); string generoMinimo = minimo.darGenero(); int precioMinimo = minimo.darPrecio(); DateTime fechaMinimo = minimo.darFecha(); minimo.cambiarTitulo(puntero1.darTitulo()); minimo.cambiarGenero(puntero1.darGenero()); minimo.cambiarPrecio(puntero1.darPrecio()); minimo.cambiarFecha(puntero1.darFecha()); puntero1.cambiarTitulo(tituloMinimo); puntero1.cambiarGenero(generoMinimo); puntero1.cambiarPrecio(precioMinimo); puntero1.cambiarFecha(fechaMinimo); } puntero1 = puntero1.getSiguiente(); } } }
private void actualizaGrilla() { grillaListas.Rows.Clear(); JuegoNodo cabeza = servicioLista.getCabeza(); int i = 0; while (cabeza != null) { i++; string[] datos = new string[5]; datos[0] = i.ToString(); datos[1] = cabeza.darTitulo(); datos[2] = cabeza.darGenero(); datos[3] = cabeza.darPrecio().ToString(); datos[4] = cabeza.darFecha().ToShortDateString(); grillaListas.Rows.Add(datos); cabeza = cabeza.getSiguiente(); } }
public void eliminarNNodos(int CantidadaEliminar) { if (verificarCabeza() == true) { throw new Exception("No hay ningun juego"); } else if (CantidadaEliminar <= 0) { throw new Exception("La cantidad especificada no es valida debe ser mayor a cero"); } else if (CantidadaEliminar > numeroRegistros) { throw new Exception("La cantidad a eliminar de ser menor o igual a: " + numeroRegistros); } else { int contador = 0; int posicion = 1; if (numeroRegistros != CantidadaEliminar) { posicion = numeroRegistros - CantidadaEliminar; } JuegoNodo temp = cabeza; while (temp != null) { contador++; if (contador == posicion) { temp.setSiguiente(null); numeroRegistros = numeroRegistros - CantidadaEliminar; break; } temp = temp.getSiguiente(); } } }