コード例 #1
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Retorna um objeto pelo seu index
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private object GetByIndex(int val)
        {
            Elemento aux = prim;

            if (val >= this.count || val < 0)
            {
                throw new InvalidIndexException(this.ToString() + ", line 56");
            }
            else if (aux == null)
            {
                throw new NullReferenceException(this.ToString() + ", line 57");
            }
            while (aux != null && val != aux.GetIndex())
            {
                aux = aux.Prox;
            }
            return(aux.GetDado());
        }
コード例 #2
0
ファイル: Lista.cs プロジェクト: hkirschke/UNO-Game
        /// <summary>
        /// Remove um elemento localizado em uma posição fornecida
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public T RemoveAt(int index)
        {
            Elemento aux = this.prim;

            for (int i = 0; i < index; i++)
            {
                if (aux.Prox != null)
                {
                    aux = aux.Prox;
                }
            }
            Elemento aux2 = aux.Prox;

            aux.Prox  = aux.Prox.Prox;
            aux2.Prox = null;
            ElementDeleted();
            Rebuild();
            return((T)aux2.GetDado());
        }
コード例 #3
0
ファイル: Lista.cs プロジェクト: hkirschke/UNO-Game
        /// <summary>
        /// Remove um elemento da lista
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public virtual T Remover(object obj)
        {
            Elemento aux = this.prim;

            while (aux.Prox != null)
            {
                if (aux.Prox.GetDado().Equals(obj))
                {
                    Elemento aux2 = aux.Prox;
                    aux.Prox  = aux.Prox.Prox;
                    aux2.Prox = null;
                    ElementDeleted();
                    Rebuild();
                    return((T)aux2.GetDado());
                }
                aux = aux.Prox;
            }
            return(default(T));
        }
コード例 #4
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Retorna um elemento pelo seu index
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private Elemento GetElementoByIndex(int val)
        {
            Elemento aux = this.prim;

            if (val > this.count || val < 0)
            {
                throw new IndexOutOfRangeException(this.ToString() + ", line 72");
            }
            else if (aux == null)
            {
                throw new NullReferenceException(this.ToString() + ", line 73");
            }

            while (val != aux.GetIndex())
            {
                aux = aux.Prox;
            }
            return(aux);
        }
コード例 #5
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Reajusta os indeces dos elementos da lista
        /// </summary>
        private void RefactoreIndex()
        {
            Elemento aux = this.prim;

            while (aux != null)
            {
                if (null != aux.Prox && aux.GetIndex() != aux.Prox.GetIndex() - 1)
                {
                    aux = aux.Prox;
                    while (aux != null)
                    {
                        aux.SetIndex(aux.GetIndex() - 1);
                        aux = aux.Prox;
                    }
                    return;
                }
                aux = aux.Prox;
            }
        }
コード例 #6
0
        /// <summary>
        /// Pega o elemento no topo da pilha, removendo-
        /// </summary>
        /// <returns></returns>
        public T Pop()
        {
            Elemento aux = this.topo.Prox;

            if (aux != null)
            {
                this.topo.Prox = aux.Prox;
                aux.Prox       = null;
                if (aux == this.fundo)
                {
                    this.fundo = this.topo;
                }
                this.count--;
                return((T)aux.GetDado());
            }
            else
            {
                return(default(T));
            }
        }
コード例 #7
0
 /// <summary>
 /// Limpa a pilha
 /// </summary>
 public void Clear()
 {
     this.topo = this.fundo = null;
 }
コード例 #8
0
 public Pilha()
 {
     this.topo  = new Elemento(null);
     this.fundo = this.topo;
 }
コード例 #9
0
ファイル: Lista.cs プロジェクト: hkirschke/UNO-Game
 public Lista()
 {
     this.prim = new Elemento(null);
     this.ult  = this.prim;
 }