public void Eliminar(int dato) { if (head != null) { if (head.Dato == dato) { head = head.Siguiente; head.Anterior = null; return; } NodoListaDoblementeEnla h = head; while (h.Siguiente != null) { if (h.Siguiente.Dato == dato) { h.Siguiente = h.Siguiente.Siguiente; if (h.Siguiente != null) { h.Siguiente.Anterior = h; } return; } h = h.Siguiente; } } }
public int ContarNodos() { int contador = 0; NodoListaDoblementeEnla h = head; while (h != null) { contador++; h = h.Siguiente; } return(contador); }
public bool BuscarDato(int a) { NodoListaDoblementeEnla h = head; if (h != null) { while (h != null) { if (h.Dato == a) { return(true); } h = h.Siguiente; } } return(false); }
private void btnInsertar_Click(object sender, EventArgs e) { try { if (!miLista.BuscarDato(int.Parse(txtNodo.Text))) { n = new NodoListaDoblementeEnla(); n.Dato = int.Parse(txtNodo.Text); miLista.Insertar(n); lblLista.Text = miLista.ToString(); txtNodo.Clear(); return; } MessageBox.Show("El dato ya existe en la lista"); txtNodo.Clear(); } catch { MessageBox.Show("Introduzca un numero valido"); } }
public void Insertar(NodoListaDoblementeEnla n) { if (head == null) { n.Anterior = null; n.Siguiente = null; head = n; return; } if (n.Dato < head.Dato) { n.Siguiente = head; n.Anterior = null; head = n; return; } NodoListaDoblementeEnla h = head; while (h.Siguiente != null) { if (h.Siguiente.Dato > n.Dato) { break; } h = h.Siguiente; //avanza al siguiente nodo } n.Siguiente = h.Siguiente; n.Anterior = h; if (h.Siguiente != null) { h.Siguiente.Anterior = n; } h.Siguiente = n; return; }
public override string ToString() { string lista = ""; NodoListaDoblementeEnla h = head; if (h != null) { lista += h.ToString(); h = h.Siguiente; while (h != null) { lista += "," + h.ToString(); h = h.Siguiente; } return(lista); } else { return("La lista esta vacia"); } }
public NodoListaDoblementeEnla() { dato = 0; siguiente = null; anterior = null; }
public NodoListaDoblementeEnla(int dato, NodoListaDoblementeEnla siguiente, NodoListaDoblementeEnla anterior) { this.dato = dato; this.siguiente = siguiente; this.anterior = anterior; }
public ListaDoblementeEnla(NodoListaDoblementeEnla n) { head = n; }
public ListaDoblementeEnla() { head = null; }