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

            do
            {
                contador++;
                h = h.Siguiente;
            } while (h != head);
            return(contador);
        }
Exemplo n.º 3
0
        public bool BuscarDato(int a)
        {
            NodoListaCircular h = head;

            if (h != null)

            {
                do
                {
                    if (h.Dato == a)
                    {
                        return(true);
                    }
                    h = h.Siguiente;
                } while (h != head);
            }
            return(false);
        }
Exemplo n.º 4
0
        public override string ToString()
        {
            string            lista = "";
            NodoListaCircular 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");
            }
        }
Exemplo n.º 5
0
        public bool Agregar(NodoListaCircular n)
        {
            NodoListaCircular 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);
        }
Exemplo n.º 6
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         if (!MiLista.BuscarDato(int.Parse(txtNodo.Text)))
         {
             n      = new NodoListaCircular();
             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.");
     }
 }
Exemplo n.º 7
0
 public NodoListaCircular(int dato, NodoListaCircular siguiente)
 {
     this.dato      = dato;
     this.siguiente = siguiente;
 }
Exemplo n.º 8
0
 public NodoListaCircular()
 {
     dato      = 0;
     siguiente = null;
 }
Exemplo n.º 9
0
 public ListaCircular(NodoListaCircular n)
 {
     head = n;
 }
Exemplo n.º 10
0
 public ListaCircular()
 {
     head = null;
 }