public void Borrar(int dato) { NodoListaCircular h = head; if (head != null) { if (head.Dato == dato) { while (h.Siguiente != head) { h = h.Siguiente; } head = head.Siguiente; h.Siguiente = head; return; } else { while (h.Siguiente.Dato != dato) { h = h.Siguiente; } h.Siguiente = h.Siguiente.Siguiente; } } }
public int ContarNodos() { int contador = 0; NodoListaCircular h = head; do { contador++; h = h.Siguiente; } while (h != head); return(contador); }
public bool BuscarDato(int a) { NodoListaCircular h = head; if (h != null) { do { if (h.Dato == a) { return(true); } h = h.Siguiente; } while (h != head); } return(false); }
public override string ToString() { string lista = ""; NodoListaCircular h = head; if (h != null) { do { lista += h.Dato + ", "; h = h.Siguiente; } while (h != head); lista += "."; lista = lista.Replace(", .", ""); return(lista); } else { return("La lista está vacía"); } }
public bool Agregar(NodoListaCircular n) { NodoListaCircular h = head; //lista vacía if (head == null) { n.Siguiente = n; head = n; return(true); } //nuevo menor que head (insertar al inicio) if (n.Dato < head.Dato) { while (h.Siguiente != head) { h = h.Siguiente; } h.Siguiente = n; n.Siguiente = head; head = n; return(true); } //insertar al final while (h.Siguiente != head) { if (n.Dato < h.Siguiente.Dato) { break; } h = h.Siguiente; } n.Siguiente = h.Siguiente; h.Siguiente = n; return(true); }
private void btnGuardar_Click(object sender, EventArgs e) { try { if (!MiLista.BuscarDato(int.Parse(txtNodo.Text))) { n = new NodoListaCircular(); n.Dato = int.Parse(txtNodo.Text); MiLista.Agregar(n); lblLista.Text = MiLista.ToString(); txtNodo.Clear(); } else { MessageBox.Show("El dato ya existe en la lista."); txtNodo.Clear(); } } catch { MessageBox.Show("Introduzca un número válido."); } }
public NodoListaCircular(int dato, NodoListaCircular siguiente) { this.dato = dato; this.siguiente = siguiente; }
public NodoListaCircular() { dato = 0; siguiente = null; }
public ListaCircular(NodoListaCircular n) { head = n; }
public ListaCircular() { head = null; }