Exemple #1
0
 public void pop()
 {
     if (this.Tamanho == 0)
     {
         throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
     }
     else
     {
         this.topo          = this.topo.Proxima;
         this.topo.Anterior = null;
         this.Tamanho--;
     }
 }
Exemple #2
0
 public void adicionaFim(T elemento)
 {
     if (this.Tamanho == 0)
     {
         adicionaInicio(elemento);
     }
     else
     {
         Celula newCelula = new Celula(elemento, null, this.ultimo);
         this.ultimo.Proxima = newCelula;
         this.ultimo         = newCelula;
         this.Tamanho++;
     }
 }
 public void adicionaFim(T elemento)
 {
     if (this.Tamanho == 0)
     {
         adicionaInicio(elemento);
     }
     else
     {
         Celula newCelula = new Celula(elemento, null, this.noCabeca.Anterior);
         this.noCabeca.Anterior.Proxima = newCelula;
         this.noCabeca.Anterior         = newCelula;
         this.Tamanho++;
     }
 }
Exemple #4
0
        public void push(T elemento)
        {
            Celula newCelula = new Celula(elemento);

            if (this.Tamanho == 0)
            {
                this.topo = newCelula;
                this.Tamanho++;
            }
            else
            {
                newCelula.Proxima = this.topo;
                this.topo         = newCelula;
                this.Tamanho++;
            }
        }
Exemple #5
0
 public void inserirNoFim(T elemento)
 {
     if (this.Tamanho == 0)
     {
         Celula newCelula = new Celula(elemento);
         this.primeiro = newCelula;
         this.ultimo   = newCelula;
         this.Tamanho++;
     }
     else
     {
         Celula newCelula = new Celula(elemento, null, this.ultimo);
         this.ultimo.Proxima = newCelula;
         this.ultimo         = newCelula;
         this.Tamanho++;
     }
 }
Exemple #6
0
        private Celula pegaCelula(int posicao)
        {
            Celula       atual = this.primeiro;
            Iterador <T> it    = new Iterador <T>(atual);

            while (it.hasNext())
            {
                for (int i = 0; i <= posicao; i++)
                {
                    atual = atual.Proxima;
                }
                break;
                it.next();
            }

            return(atual);
        }
Exemple #7
0
        public void adicionaInicio(T elemento)
        {
            Celula newCelula = new Celula(elemento);

            if (this.Tamanho == 0)
            {
                this.primeiro = newCelula;
                this.ultimo   = newCelula;
                this.Tamanho++;
            }
            else
            {
                newCelula.Proxima = this.primeiro;
                this.primeiro     = newCelula;
                this.Tamanho++;
            }
        }
 public void adicionaInicio(T elemento)
 {
     if (this.Tamanho == 0)
     {
         Celula newCelula = new Celula(elemento);
         this.noCabeca.Proxima  = newCelula;
         this.noCabeca.Anterior = newCelula;
         this.Tamanho++;
     }
     else
     {
         Celula newCelula = new Celula(elemento);
         newCelula.Proxima = this.noCabeca.Proxima;
         this.noCabeca.Proxima.Anterior = newCelula;
         this.noCabeca.Proxima          = newCelula;
         this.Tamanho++;
     }
 }
Exemple #9
0
 public void inserirNoInicio(T elemento)
 {
     if (this.Tamanho == 0)
     {
         Celula newCelula = new Celula(elemento);
         this.primeiro = newCelula;
         this.ultimo   = newCelula;
         this.Tamanho++;
     }
     else
     {
         Celula newCelula = new Celula(elemento);
         newCelula.Proxima      = this.primeiro;
         this.primeiro.Anterior = newCelula;
         this.primeiro          = newCelula;
         this.Tamanho++;
     }
 }
Exemple #10
0
        public void removeInicio()
        {
            if (this.Tamanho == 0)
            {
                throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
            }

            else if (this.primeiro == this.ultimo)
            {
                this.primeiro = null;
                this.ultimo   = null;
                this.Tamanho--;
            }
            else
            {
                this.primeiro = this.primeiro.Proxima;
                this.Tamanho--;
            }
        }
Exemple #11
0
        public void adiciona(T elemento, int posicao)
        {
            if (this.Tamanho == 0 || posicao < 0 || posicao > this.Tamanho)
            {
                throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
            }

            else if (posicao == 0)
            {
                adicionaInicio(elemento);
            }

            else if (posicao == this.Tamanho)
            {
                adicionaFim(elemento);
            }

            else
            {
                Celula       atual     = this.primeiro;
                Celula       aux       = this.pegaCelula(posicao - 2);
                Celula       newCelula = new Celula(elemento);
                Iterador <T> it        = new Iterador <T>(atual);
                while (it.hasNext())
                {
                    for (int i = 0; i <= posicao; i++)
                    {
                        atual = atual.Proxima;
                        if (i == posicao)
                        {
                            if (atual != null)
                            {
                                newCelula.Proxima = aux.Proxima;
                                aux.Proxima       = newCelula;
                            }
                        }
                    }
                    break;
                    it.next();
                }
                this.Tamanho++;
            }
        }
        public void remove(int posicao)
        {
            if (this.Tamanho == 0 || posicao < 0 || posicao > this.Tamanho)
            {
                throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
            }

            else if (this.noCabeca.Proxima == this.noCabeca.Anterior)
            {
                this.noCabeca.Proxima  = null;
                this.noCabeca.Anterior = null;
                this.Tamanho--;
            }

            else if (posicao == 0)
            {
                this.removeInicio();
            }

            else
            {
                Celula       atual = this.noCabeca.Proxima;
                Iterador <T> it    = new Iterador <T>(atual);
                while (it.hasNext())
                {
                    for (int i = 0; i != posicao - 1; i++)
                    {
                        atual = atual.Proxima;
                    }
                    if (atual != null)
                    {
                        atual.Anterior = atual.Proxima;
                        atual.Proxima  = atual.Anterior.Proxima;
                        atual          = atual.Anterior.Proxima;
                    }
                    break;
                    it.next();
                }
                this.Tamanho--;
            }
        }
Exemple #13
0
        public void removerFim()
        {
            if (this.Tamanho == 0)
            {
                throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
            }

            else if (this.primeiro == this.ultimo)
            {
                this.primeiro = null;
                this.ultimo   = null;
                this.Tamanho--;
            }

            else
            {
                this.Tamanho--;
                Celula atual = this.ultimo;
                this.ultimo = atual.Anterior;
            }
        }
        public void removeFim()
        {
            if (this.Tamanho == 0)
            {
                throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
            }

            else if (this.noCabeca.Proxima == this.noCabeca.Anterior)
            {
                this.noCabeca.Proxima  = null;
                this.noCabeca.Anterior = null;
                this.Tamanho--;
            }

            else
            {
                this.Tamanho--;
                Celula atual = this.noCabeca.Anterior;
                this.noCabeca.Proxima = atual.Anterior;
            }
        }
Exemple #15
0
        public void remove(int posicao)
        {
            if (this.Tamanho == 0 || posicao < 0 || posicao >= this.Tamanho)
            {
                throw new ArgumentOutOfRangeException("Argumento fora de alcance.");
            }

            else if (this.primeiro == this.ultimo)
            {
                this.primeiro = null;
                this.ultimo   = null;
                this.Tamanho--;
            }

            else
            {
                Celula       atual = this.primeiro;
                Celula       aux   = this.pegaCelula(posicao - 2);
                Celula       aux2  = this.pegaCelula(posicao);
                Iterador <T> it    = new Iterador <T>(atual);
                while (it.hasNext())
                {
                    for (int i = 0; i <= posicao; i++)
                    {
                        atual = atual.Proxima;
                        if (i == posicao)
                        {
                            if (atual != null)
                            {
                                atual         = aux;
                                atual.Proxima = aux2;
                            }
                        }
                    }
                    break;
                    it.next();
                }
                this.Tamanho--;
            }
        }
Exemple #16
0
        public bool existeDado(T elemento)
        {
            Celula atual = this.primeiro;
            bool   cond  = false;

            for (int i = 0; i < this.Tamanho; i++)
            {
                if (atual.Elemento.Equals(elemento))
                {
                    cond = true;
                    break;
                }

                if (atual.Proxima != null)
                {
                    atual = atual.Proxima;
                }
                else
                {
                    break;
                }
            }
            return(cond);
        }
Exemple #17
0
 public Deque()
 {
     this.primeiro = null;
     this.ultimo   = null;
     this.Tamanho  = 0;
 }
Exemple #18
0
 public Pilha()
 {
     this.topo    = null;
     this.Tamanho = 0;
 }
Exemple #19
0
 public Fila()
 {
     this.primeiro = null;
     this.ultimo   = null;
     this.Tamanho  = 0;
 }
 public ListaDuplamenteEncadeadaComNoCabeca()
 {
     this.noCabeca = new Celula(null, null, null);
     this.Tamanho  = 0;
 }
Exemple #21
0
 public ListaEncadeada()
 {
     this.primeiro = null;
     this.ultimo   = null;
     this.Tamanho  = 0;
 }
Exemple #22
0
 public void limpa()
 {
     this.topo = null;
     GC.Collect();
     this.Tamanho = 0;
 }