Esempio n. 1
0
        //METODO
        public void Agregar(NodolistaS n)
        {
            //LA LISTA ESTA VACIA :) :B
            if (head == null)
            {
                head = n;
                return;
            }

            //INSERCION AL INICIO
            if (n.Numero < head.Numero)
            {
                n.Siguiente = head;
                head        = n;
                return;
            }

            //CIPIAR A HEAD..... PARA PODER RECORRER
            NodolistaS h = head;

            while (h.Siguiente != null)
            {
                if (n.Numero < h.Siguiente.Numero)
                {
                    break;
                }
                h = h.Siguiente;
            }
            n.Siguiente = h.Siguiente;
            h.Siguiente = n;
        }
Esempio n. 2
0
        public void eliminar(int n)
        {
            NodolistaS h = head;

            while (h != null)
            {
                NodolistaS anterior, nodo;
                nodo     = head;
                anterior = null;

                while (nodo != null && nodo.Numero < n)
                {
                    anterior = nodo;
                    nodo     = nodo.Siguiente;
                }
                if (nodo == null || nodo.Numero != n)
                {
                    return;
                }
                else
                {
                    if (anterior == null)
                    {
                        head = nodo.Siguiente;
                    }
                    else
                    {
                        anterior.Siguiente = nodo.Siguiente;
                    }
                }
                h = h.Siguiente;
            }
        }
Esempio n. 3
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            int        numero = int.Parse(txtNumero.Text);
            string     nombre = txtNombre.Text;
            NodolistaS n      = new NodolistaS(numero, nombre, null);

            //Lista.head = n;
            lista.eliminar(numero);
        }
Esempio n. 4
0
        public int CuentaNodos()
        {
            int        cuenta = 0;
            NodolistaS h      = head;

            while (h != null)
            {
                cuenta++;
                h = h.Siguiente;
            }
            return(cuenta);
        }
Esempio n. 5
0
        public override string ToString()
        {
            string     lista = "";
            NodolistaS h     = head;

            while (h != null)
            {
                lista += h.Numero + " ";
                h      = h.Siguiente;
            }

            return(lista);
        }
Esempio n. 6
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            int        numero = int.Parse(txtNumero.Text);
            string     nombre = txtNombre.Text;
            NodolistaS n      = new NodolistaS(numero, nombre, null);

            // lista.Head = n;
            lista.Agregar(n);

            txtNombre.Text = string.Empty;
            txtNumero.Text = string.Empty;
            txtNumero.Focus();
        }
Esempio n. 7
0
        public bool Buscar(int b)
        {
            NodolistaS h = head;

            while (h != null)
            {
                if (h.Numero == b)
                {
                    return(true);
                }

                h = h.Siguiente;
            }
            return(false);
        }
Esempio n. 8
0
 //CONSTRUCTORES
 public NodolistaS(int numero, string nombre, NodolistaS siguiente)
 {
     this.numero    = numero;
     this.nombre    = nombre;
     this.siguiente = siguiente;
 }
Esempio n. 9
0
 public void Vaciar()
 {
     head = null;
 }
Esempio n. 10
0
 public ListaSimple1(NodolistaS x)
 {
     head = x;
 }
Esempio n. 11
0
 public ListaSimple1()
 {
     head = null;
 }