public bool Eliminar(int b)
        {
            if (Buscar(b))
            {
                NodoLEDC h = head;

                while (h.Siguiente != head)
                {
                    if (h.Dato == b)
                    {
                        break;
                    }

                    h = h.Siguiente;
                }
                h.Atras.Siguiente = h.Siguiente;
                h.Siguiente.Atras = h.Atras;
                if (h == head)
                {
                    head = head.Siguiente;
                }

                return(true);
            }
            return(false);
        }
        public string MostrarDatosAnt()
        {
            NodoLEDC h = head;
            string   s = "";

            do
            {
                s += h.Atras.Dato;
                h  = h.Atras;
            } while (h != head);
            return(s);
        }
        public string MostrarDatos()
        {
            NodoLEDC h = head;
            string   s = "";

            do
            {
                s += h.Dato + "-";
                h  = h.Siguiente;
            } while (h != head);
            return(s);
        }
        public bool Agregar(NodoLEDC n)
        {
            NodoLEDC h = head;

            if (head == null)
            {
                n.Atras     = n;
                n.Siguiente = n;
                head        = n;
                return(true);
            }
            if (Buscar(n.Dato))
            {
                return(false);
            }

            if (n.Dato < head.Dato)
            {
                head.Atras.Siguiente = n;
                n.Atras     = head.Atras;
                n.Siguiente = head;
                head.Atras  = n;
                head        = n;
                return(true);
            }
            do
            {
                if (n.Dato < h.Siguiente.Dato)
                {
                    break;
                }
                h = h.Siguiente;
            } while (h != head);
            if (n.Dato < h.Siguiente.Dato)
            {
                h.Siguiente.Atras = n;
                n.Atras           = h;
                n.Siguiente       = h.Siguiente;
                h.Siguiente       = n;
            }
            else
            {
                n.Siguiente       = h;
                n.Atras           = h.Atras;
                h.Atras.Siguiente = n;
                h.Atras           = n;
            }
            return(true);
        }
        public int ContarNodos()
        {
            int cuenta = 0;

            if (head != null)
            {
                NodoLEDC h = head;
                do
                {
                    cuenta++;
                    h = h.Siguiente;
                } while (h != head);
            }
            return(cuenta);
        }
        public bool Buscar(int b)
        {
            NodoLEDC h = head;

            if (h != null)
            {
                do
                {
                    if (h.Dato == b)
                    {
                        return(true);
                    }
                    h = h.Siguiente;
                } while (h != head);
            }
            return(false);
        }
        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 NodoLEDC();
                    n.Dato = int.Parse(Lista[contador]);
                    MiLista.Agregar(n);
                    lblLista.Text = MiLista.ToString();
                    contador++;
                }
            }
        }
        public override string ToString()
        {
            string   lista = "";
            NodoLEDC 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 BtnGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         if (!MiLista.Buscar(int.Parse(txtNodo.Text)))
         {
             n      = new NodoLEDC();
             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.");
     }
 }
Exemple #10
0
 public NodoLEDC(int dato, NodoLEDC siguiente)
 {
     this.Dato      = dato;
     this.Siguiente = siguiente;
 }
Exemple #11
0
 public NodoLEDC()
 {
     dato      = 0;
     siguiente = null;
 }
 public ListaDoblementeEnlazadaCircularOperaciones(NodoLEDC n)
 {
     head        = n;
     n.Atras     = head;
     n.Siguiente = head;
 }
 public ListaDoblementeEnlazadaCircularOperaciones()
 {
     head = null;
 }
 public void Vaciar()
 {
     head = null;
 }