Ejemplo n.º 1
0
 public T Eliminar(int i)
 {
     try
     {
         NodoL <T> x;
         if (i == 0)
         {
             x = this.Cabeza.GetSig();
             this.Cabeza.SetSig(x.GetSig());
             this.Cabeza.GetSig().SetAnt(this.Cabeza);
             x.SetSig(null);
             x.SetAnt(null);
             this.Tamanio--;
             return(x.GetInfo());
         }
         x = this.GetPos(i - 1);
         if (x == null)
         {
             return(default(T));
         }
         NodoL <T> y = x.GetSig();
         x.SetSig(y.GetSig());
         y.GetSig().SetAnt(x);
         y.SetSig(null);
         y.SetAnt(null);
         this.Tamanio--;
         return(y.GetInfo());
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(default(T));
 }
Ejemplo n.º 2
0
        public T Eliminar(T pDato)
        {
            NodoL <T> temp = this.Cabeza, anterior = this.Cabeza;
            int       longit = this.GetTamanio();
            int       rta;

            for (int i = 0; i < this.GetTamanio(); i++)
            {
                rta = Comparable.GetInstancia().Compare(Cabeza.GetInfo(), pDato);
                if (rta == 0 && i == 0)
                {
                    this.Cabeza  = temp.GetSig();
                    longit       = longit - 1;
                    this.Tamanio = longit;
                }
                rta = Comparable.GetInstancia().Compare(temp.GetInfo(), pDato);
                if (rta == 0 && i > 0)
                {
                    anterior.SetSig(temp.GetSig());
                    longit       = longit - 1;
                    this.Tamanio = longit;
                }
                anterior = temp;
                temp     = temp.GetSig();
            }
            return(default(T));
        }
Ejemplo n.º 3
0
        public bool EnColar(NodoL <T> pNodo)
        {
            bool      result = false;
            NodoL <T> aux;

            pNodo.SetSig(null);
            if (this.EsVacia() || this.Tamanio == 0)
            {
                this.Inicio = pNodo;
                result      = true;
            }
            else
            {
                aux = this.Inicio;
                bool bandera = true;
                while (bandera)
                {
                    if (aux.GetSig() == null)
                    {
                        aux.SetSig(pNodo);
                        result  = true;
                        bandera = false;
                    }
                    aux = aux.GetSig();
                }
            }
            int longt = this.GetTamanio();

            longt        = longt + 1;
            this.Tamanio = longt;
            return(result);
        }
Ejemplo n.º 4
0
        public bool InsertarAlInicio(NodoL <T> pNodo)
        {
            bool result = false;

            if (this.EsVacia())
            {
                pNodo.SetSig(null);
                this.Cabeza = pNodo;
                result      = true;
            }
            else
            {
                pNodo.SetSig(this.Cabeza);
                this.Cabeza = pNodo;
                result      = true;
            }
            int longt = this.GetTamanio();

            longt        = longt + 1;
            this.Tamanio = longt;
            return(result);
        }
Ejemplo n.º 5
0
        public bool InsertarOrdenado(T pDato)
        {
            bool      result  = false;
            NodoL <T> newNode = new NodoL <T>(pDato, null);

            if (this.EsVacia())
            {
                this.Cabeza = newNode;
                result      = true;
            }
            else
            {
                NodoL <T> temp = Cabeza;
                int       rta  = Comparable.GetInstancia().Compare(Cabeza.GetInfo(), pDato);
                if (rta == 1)
                {
                    newNode.SetSig(Cabeza);
                    this.Cabeza = newNode;
                    result      = true;
                }
                else
                {
                    while ((temp.GetSig() != null) && (Comparable.GetInstancia().Compare(temp.GetSig().GetInfo(), pDato) < 0))
                    {
                        temp = temp.GetSig();
                    }
                    newNode.SetSig(temp.GetSig());
                    temp.SetSig(newNode);
                    result = true;
                }
            }
            int longt = this.GetTamanio();

            longt        = longt + 1;
            this.Tamanio = longt;
            return(result);
        }
Ejemplo n.º 6
0
        private bool Enlazar(NodoL <T> cabeza, ListD <T> lista)
        {
            bool result = false;

            if (cabeza.GetSig() is null)
            {
                cabeza.SetSig(lista.GetCabeza());
                result = true;
            }
            else
            {
                result = Enlazar(cabeza.GetSig(), lista);
            }
            return(result);
        }
Ejemplo n.º 7
0
        public T DeColar()
        {
            if (this.EsVacia())
            {
                return(default(T));
            }
            NodoL <T> x = this.Inicio.GetSig();

            this.Inicio.SetSig(x.GetSig());
            x.GetSig().SetAnt(Inicio);
            x.SetSig(null);
            x.SetAnt(null);
            this.Tamanio--;
            return(x.GetInfo());
        }
Ejemplo n.º 8
0
        public void Apilar(NodoL <T> pNodo)
        {
            if (this.EsVacia())
            {
                this.Tope = pNodo;
            }
            else
            {
                pNodo.SetSig(this.Tope);
                this.Tope = pNodo;
            }
            int longt = this.GetTamanio();

            longt        = longt + 1;
            this.Tamanio = longt;
        }
Ejemplo n.º 9
0
        public bool InsertarAlFinal(T pDato)
        {
            bool      result = false;
            NodoL <T> newNode = new NodoL <T>(pDato), aux;

            newNode.SetSig(null);
            if (this.EsVacia())
            {
                this.Cabeza = newNode;
                result      = true;
            }
            else
            {
                int rta = Comparable.GetInstancia().Compare(this.Cabeza.GetInfo(), 0);
                if (rta == 0 && this.Cabeza.GetSig() == null && this.Tamanio == 0)
                {
                    this.Cabeza = newNode;
                    result      = true;
                }
                else
                {
                    aux = this.Cabeza;
                    bool bandera = true;
                    while (bandera)
                    {
                        if (aux.GetSig() == null)
                        {
                            aux.SetSig(newNode);
                            result  = true;
                            bandera = false;
                        }
                        aux = aux.GetSig();
                    }
                }
            }

            int longt = this.GetTamanio();

            longt        = longt + 1;
            this.Tamanio = longt;

            return(result);
        }
Ejemplo n.º 10
0
        public bool InsertarAlInicio(T pDato)
        {
            bool      result  = false;
            NodoL <T> newNode = new NodoL <T>(pDato);

            if (this.EsVacia())
            {
                this.Cabeza = newNode;
                result      = true;
            }
            else
            {
                newNode.SetSig(this.Cabeza);
                this.Cabeza = newNode;
                result      = true;
            }
            int longt = this.GetTamanio();

            longt        = longt + 1;
            this.Tamanio = longt;
            return(result);
        }