コード例 #1
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));
        }
コード例 #2
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));
 }
コード例 #3
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);
        }
コード例 #4
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());
        }
コード例 #5
0
 private NodoL <T> GetPos(int i)
 {
     if (i < 0 || i >= this.GetTamanio())
     {
         Console.WriteLine("Error indice no valido en una Lista Circular!");
         return(null);
     }
     else
     {
         NodoL <T> x = this.Cabeza;
         for (int j = 0; j < i && x.GetSig() != null; j++)
         {
             x = x.GetSig();
         }
         return(x);
     }
 }
コード例 #6
0
        public T Next()
        {
            if (!this.HasNext())
            {
                Console.WriteLine("No hay mas elementos");
                return(default(T));
            }
            NodoL <T> nodoActual = Nodo;

            Nodo = Nodo.GetSig();
            return(nodoActual.GetInfo());
        }
コード例 #7
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);
        }
コード例 #8
0
        public Object[] AVector()
        {
            if (this.EsVacia())
            {
                return(null);
            }
            Object[]  vector = new Object[this.GetTamanio()];
            NodoL <T> actual = this.Cabeza;

            for (int i = 0; i < this.GetTamanio(); i++)
            {
                vector[i] = actual;
                actual    = actual.GetSig();
            }
            return(vector);
        }
コード例 #9
0
        public T Desapilar()
        {
            if (this.EsVacia())
            {
                return(default(T));
            }
            NodoL <T> x = this.Tope;

            this.Tope = Tope.GetSig();
            this.Tamanio--;
            if (Tamanio == 0)
            {
                this.Tope = null;
            }
            return(x.GetInfo());
        }
コード例 #10
0
 private NodoL <T> GetPos(int i)
 {
     if (i < 0 || i >= this.GetTamanio())
     {
         Console.WriteLine("Error indice no valido en una Lista Circular!");
         return(null);
     }
     else
     {
         NodoL <T> x = this.Tope.GetSig();
         for (; i-- > 0; x = x.GetSig())
         {
             return(x);
         }
     }
     return(null);
 }
コード例 #11
0
        public int GetIndice(T dato)
        {
            int i = -1;

            if (Cabeza.GetSig() is null)
            {
                return(-1);
            }
            for (NodoL <T> x = this.Cabeza.GetSig(); x != this.Cabeza && x != null; x = x.GetSig())
            {
                if (x.GetInfo().Equals(dato))
                {
                    return(i);
                }
                i++;
            }
            return(-1);
        }