Ejemplo n.º 1
0
        private void btnCargar_Click(object sender, EventArgs e)
        {
            OpenFileDialog Seleccionar = new OpenFileDialog();

            try
            {
                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 NodoDoble();
                        n.Dato = int.Parse(Lista[contador]);
                        miLista.Agregar(n);
                        lblLista.Text = miLista.ToString();
                        contador++;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error al cargar");
                miLista.Head  = null;
                lblLista.Text = miLista.ToString();
                return;
            }
        }
Ejemplo n.º 2
0
        public void Eliminar(int dato)
        {
            if (head != null)
            {
                if (head.Dato == dato)
                {
                    head          = head.Siguiente;
                    head.Anterior = null;
                    return;
                }
                NodoDoble h = head;

                while (h.Siguiente != null)
                {
                    if (h.Siguiente.Dato == dato)
                    {
                        break;
                    }
                    h = h.Siguiente;
                }
                if (h.Siguiente.Siguiente == null)
                {
                    h.Siguiente = null;
                }
                else
                {
                    h.Siguiente          = h.Siguiente.Siguiente;
                    h.Siguiente.Anterior = h;
                }
            }
        }
Ejemplo n.º 3
0
        public int ContarNodos()
        {
            int       contador = 0;
            NodoDoble h        = head;

            while (h != null)
            {
                contador++;
                h = h.Siguiente;
            }
            return(contador);
        }
        public int ContarNodos()
        {
            int contador = 0;

            if (head != null)
            {
                NodoDoble h = head;
                do
                {
                    contador++;
                    h = h.Siguiente;
                } while (h != head);
            }
            return(contador);
        }
Ejemplo n.º 5
0
        public bool BuscarDato(int a)
        {
            NodoDoble h = head;

            if (h != null)
            {
                while (h != null)
                {
                    if (h.Dato == a)
                    {
                        return(true);
                    }
                    h = h.Siguiente;
                }
            }
            return(false);
        }
        public bool Buscar(int b) //metodo para buscar un nodo
        {
            NodoDoble h = head;

            if (h != null)
            {
                do
                {
                    if (h.Dato == b)
                    {
                        return(true);
                    }
                    h = h.Siguiente;
                } while (h != head);
            }
            return(false);
        }
        public void Agregar(NodoDoble n)
        {
            NodoDoble h = head;

            if (head == null)
            {
                head           = n;
                head.Anterior  = head;
                head.Siguiente = head;
                return;
            }

            if (n.Dato < head.Dato)
            {
                head.Anterior.Siguiente = n;
                n.Anterior    = head.Anterior;
                n.Siguiente   = head;
                head.Anterior = n;
                head          = n;
                return;
            }

            do
            {
                if (n.Dato < h.Siguiente.Dato)
                {
                    break;
                }
                h = h.Siguiente;
            } while (h != head);
            if (n.Dato < h.Siguiente.Dato)
            {
                h.Siguiente.Anterior = n;
                n.Anterior           = h;
                n.Siguiente          = h.Siguiente;
                h.Siguiente          = n;
            }
            else
            {
                n.Siguiente          = h;
                n.Anterior           = h.Anterior;
                h.Anterior.Siguiente = n;
                h.Anterior           = n;
            }
        }
        public void Eliminar(int b)
        {
            NodoDoble h = head;

            while (h.Siguiente != head)
            {
                if (h.Dato == b)
                {
                    break;
                }
                h = h.Siguiente;
            }
            h.Anterior.Siguiente = h.Siguiente;
            h.Siguiente.Anterior = h.Anterior;
            if (h == head)
            {
                head = head.Siguiente;
            }
        }
        public override string ToString()
        {
            string    lista = "";
            NodoDoble 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 btnAgregar_Click(object sender, EventArgs e)
 {
     try
     {
         if (!miLista.BuscarDato(int.Parse(txtNodo.Text)))
         {
             n      = new NodoDoble();
             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 dato valido");
     }
 }
Ejemplo n.º 11
0
        public override string ToString()
        {
            string    lista = "";
            NodoDoble 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");
            }
        }
Ejemplo n.º 12
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         int dato = int.Parse(txtDato.Text);
         if (miLista.Buscar(dato) == false)
         {
             n      = new NodoDoble();
             n.Dato = dato;
             miLista.Agregar(n);
             lblLista.Text = miLista.ToString();
             txtDato.Clear();
             return;
         }
         MessageBox.Show("El dato ya se encuentra dentro de la lista");
     }
     catch
     {
         MessageBox.Show("Introduzca un dato valido");
         txtDato.Clear();
         return;
     }
 }
Ejemplo n.º 13
0
        public void Insertar(NodoDoble n)
        {
            if (head == null)
            {
                head = n;
                return;
            }

            if (n.Dato < head.Dato)
            {
                n.Siguiente   = head;
                head.Anterior = n;
                head          = n;
                return;
            }

            NodoDoble 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;
        }
Ejemplo n.º 14
0
 public NodoDoble()
 {
     dato      = 0;
     siguiente = null;
     anterior  = null;
 }
Ejemplo n.º 15
0
 public ListaDoblementeEnlazada()
 {
     head = null;
 }
 public ListaCircDoble()
 {
     head = null;
 }
 public ListaCircDoble(NodoDoble n)
 {
     head        = n;
     n.Anterior  = head;
     n.Siguiente = head;
 }