Example #1
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);
        }
Example #2
0
        public bool EnColar(T pDato)
        {
            bool      result = false;
            NodoL <T> newNode = new NodoL <T>(pDato, null), aux;

            if (this.EsVacia() || this.Tamanio == 0)
            {
                this.Inicio = newNode;
                result      = true;
            }
            else
            {
                aux = this.Inicio;
                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);
        }
Example #3
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));
 }
Example #4
0
 public Queue()
 {
     this.Inicio = new NodoL <T>();
     this.Inicio.SetSig(null);
     Inicio.SetAnt(Inicio);
     this.Tamanio = 0;
 }
Example #5
0
        public NodoL <T> ElimiAlFinal()
        {
            NodoL <T> aux, eliminado = null;
            int       longt = this.GetTamanio();

            if (longt > 0)
            {
                if (longt == 1)
                {
                    this.Cabeza = null;
                }
                else
                {
                    aux = this.Cabeza;
                    bool bandera = true;
                    while (bandera)
                    {
                        if (aux.GetSig().GetSig() == null)
                        {
                            eliminado = aux.GetSig();
                            aux.SetSig(null);
                            bandera = false;
                            break;
                        }
                        aux = aux.GetSig();
                    }
                }
                longt        = longt - 1;
                this.Tamanio = longt;
            }
            return(eliminado);
        }
Example #6
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));
        }
Example #7
0
 public void Apilar(T info)
 {
     if (this.EsVacia())
     {
         this.Tope = new NodoL <T>(info, null);
     }
     else
     {
         this.Tope = new NodoL <T>(info, this.Tope);
     }
     this.Tamanio++;
 }
Example #8
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());
        }
Example #9
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());
        }
Example #10
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);
        }
Example #11
0
 public void Set(int i, T dato)
 {
     try
     {
         NodoL <T> t = this.GetPos(i);
         if (t == null)
         {
             return;
         }
         t.SetInfo(dato);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #12
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);
        }
Example #13
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;
        }
Example #14
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());
        }
Example #15
0
 public T Get(int i)
 {
     try
     {
         NodoL <T> x = this.GetPos(i);
         if (x == null)
         {
             return(default(T));
         }
         return(x.GetInfo());
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     return(default(T));
 }
Example #16
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);
     }
 }
Example #17
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);
 }
Example #18
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);
        }
Example #19
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);
        }
Example #20
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);
        }
Example #21
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);
        }
Example #22
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);
        }
Example #23
0
 public ListD()
 {
     this.Cabeza = null;
 }
Example #24
0
 public NodoL()
 {
     this.Info     = default(T);
     this.Sig      = null;
     this.Anterior = null;
 }
Example #25
0
 public NodoL(T info)
 {
     this.Info     = info;
     this.Sig      = null;
     this.Anterior = null;
 }
Example #26
0
 public NodoL(T info, NodoL <T> sig)
 {
     this.Info = info;
     this.Sig  = sig;
 }
Example #27
0
 public NodoL(T info, NodoL <T> sig, NodoL <T> anterior)
 {
     this.Info     = info;
     this.Sig      = sig;
     this.Anterior = anterior;
 }
Example #28
0
 public void SetSig(NodoL <T> nuevo)
 {
     this.Sig = nuevo;
 }
Example #29
0
 public void SetAnt(NodoL <T> anterior)
 {
     this.Anterior = anterior;
 }
Example #30
0
 public ListD(T pPato)
 {
     this.Cabeza = new NodoL <T>(pPato);
     this.Cabeza.SetSig(null);
 }