public void Borrar(int dato) { NodoLCS 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; NodoLCS h = head; do { contador++; h = h.Siguiente; } while (h != head); return(contador); }
public bool BuscarDato(int a) { NodoLCS 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 = ""; NodoLCS 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"); } }
private void BtnCargar_Click(object sender, EventArgs e) { OpenFileDialog Seleccionar = new OpenFileDialog(); if (Seleccionar.ShowDialog() == DialogResult.OK) { MiLista.Head = null; int contador = 0; string ruta = Seleccionar.FileName; string linea = File.ReadAllText(ruta); string[] Lista = linea.Split(','); foreach (string i in Lista) { n = new NodoLCS(); n.Dato = int.Parse(Lista[contador]); MiLista.Agregar(n); lblLista.Text = MiLista.ToString(); contador++; } } }
public bool Agregar(NodoLCS n) { NodoLCS 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 NodoLCS(); 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 ListaCircularSimpleOperaciones(NodoLCS n) { head = n; }
public ListaCircularSimpleOperaciones() { head = null; }
public NodoLCS(int dato, NodoLCS siguiente) { this.dato = dato; this.siguiente = siguiente; }
public NodoLCS() { dato = 0; siguiente = null; }