public void Eliminar(int dato)
        {
            if (head != null)
            {
                if (head.Dato == dato)
                {
                    head          = head.Siguiente;
                    head.Anterior = null;
                    return;
                }
                NodoLDE 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;
            NodoLDE h        = head;

            while (h != null)
            {
                contador++;

                h = h.Siguiente;
            }
            return(contador);
        }
        public bool BuscarDato(int a)
        {
            NodoLDE h = head;

            if (h != null)
            {
                while (h != null)
                {
                    if (h.Dato == a)
                    {
                        return(true);
                    }
                    h = h.Siguiente;
                }
            }
            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 NodoLDE();
                    n.Dato = int.Parse(Lista[contador]);
                    miLista.Insertar(n);
                    lblLista.Text = miLista.ToString();
                    contador++;
                }
            }
        }
 private void BtnGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         if (!miLista.BuscarDato(int.Parse(txtNodo.Text)))
         {
             n      = new NodoLDE();
             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(NodoLDE 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;
            }

            NodoLDE h = head;

            while (h.Siguiente != null)
            {
                if (h.Siguiente.Dato > n.Dato)
                {
                    break;
                }
                h = h.Siguiente;
            }

            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 = "";
            NodoLDE 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 ListaDoblementeEnlazadaOperaciones(NodoLDE n)
 {
     head = n;
 }
 public ListaDoblementeEnlazadaOperaciones()
 {
     head = null;
 }
示例#10
0
 public NodoLDE()
 {
     dato      = 0;
     siguiente = null;
     anterior  = null;
 }
示例#11
0
 public NodoLDE(int dato, NodoLDE siguiente, NodoLDE anterior)
 {
     this.dato      = dato;
     this.siguiente = siguiente;
     this.anterior  = anterior;
 }