Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
        public int ContarNodos()
        {
            int contador = 0;
            NodoListaDoblementeEnla h = head;

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

                h = h.Siguiente;
            }
            return(contador);
        }
Exemplo n.º 3
0
        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");
     }
 }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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");
            }
        }
Exemplo n.º 7
0
 public NodoListaDoblementeEnla()
 {
     dato      = 0;
     siguiente = null;
     anterior  = null;
 }
Exemplo n.º 8
0
 public NodoListaDoblementeEnla(int dato, NodoListaDoblementeEnla siguiente, NodoListaDoblementeEnla anterior)
 {
     this.dato      = dato;
     this.siguiente = siguiente;
     this.anterior  = anterior;
 }
Exemplo n.º 9
0
 public ListaDoblementeEnla(NodoListaDoblementeEnla n)
 {
     head = n;
 }
Exemplo n.º 10
0
 public ListaDoblementeEnla()
 {
     head = null;
 }