コード例 #1
0
ファイル: Lista.cs プロジェクト: hkirschke/UNO-Game
        /// <summary>
        /// Procura um elemento
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public T Find(T obj)
        {
            Elemento aux = this.prim;

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

            if (val == 0)
            {
                return(aux.GetDado());
            }
            while (aux != null && val <= count && val != auxcount && auxcount < val && auxcount < actualIndexPosition)
            {
                aux = aux.Prox;
                auxcount++;
            }
            return(aux.GetDado());
        }
コード例 #3
0
ファイル: Lista.cs プロジェクト: juliocnp/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 auxret = aux.Prox;

            aux.Prox = auxret.Prox;
            if (auxret == this.ult)
            {
                this.ult = aux;
            }
            else
            {
                auxret.Prox = null;
            }

            this.ElementDeleted();
            this.Rebuild();
            this.RefactoreIndex();
            return((T)auxret.GetDado());
        }
コード例 #4
0
ファイル: Lista.cs プロジェクト: juliocnp/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) && (!aux.Prox.GetDado().Equals(obj)))
            {
                aux = aux.Prox;
            }
            if (aux.Prox != null)
            {
                Elemento auxret = aux.Prox;
                aux.Prox = auxret.Prox;
                if (auxret == this.ult)
                {
                    this.ult = aux;
                }
                else
                {
                    auxret.Prox = null;
                }

                this.ElementDeleted();
                this.Rebuild();
                this.RefactoreIndex();
                return((T)auxret.GetDado());
            }
            else
            {
                return(default(T));
            }
        }
コード例 #5
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Remove o primeiro elemento da lista
        /// </summary>
        /// <returns></returns>
        public virtual T RemoveFirst()
        {
            if (this.prim.Prox != null)
            {
                Elemento aux    = this.prim;
                Elemento auxret = aux.Prox;
                aux.Prox = auxret.Prox;
                if (auxret == this.ult)
                {
                    this.ult = aux;
                }
                else
                {
                    auxret.Prox = null;
                }

                this.ElementDeleted();
                this.Rebuild();
                this.RefactoreIndex();
                return((T)auxret.GetDado());
            }
            else
            {
                return(default(T));
            }
        }
コード例 #6
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Retorna o index de um elemento
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int GetIndexOf(object obj)
        {
            Elemento aux = prim;

            while (aux != null && aux.GetDado() != obj)
            {
                aux = aux.Prox;
            }
            return(aux.GetIndex());
        }
コード例 #7
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Através de um objeto, verifica se o mesmo existe na lista
        /// </summary>
        /// <param name="dado"></param>
        /// <returns></returns>
        private Elemento GetElementOnList(object dado)
        {
            Elemento aux = this.prim.Prox;

            while (aux.GetDado() != dado || aux == null)
            {
                aux = aux.Prox;
            }
            return(aux);
        }
コード例 #8
0
ファイル: Lista.cs プロジェクト: hkirschke/UNO-Game
        /// <summary>
        /// Retorna o index de um elemento
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int GetIndexOf(object obj)
        {
            int      auxcount = 0;
            Elemento aux      = prim.Prox;

            while (aux != null || aux.GetDado() == obj)
            {
                aux = aux.Prox;
                auxcount++;
            }
            return(count);
        }
コード例 #9
0
ファイル: Lista.cs プロジェクト: juliocnp/UNO-Game
        /// <summary>
        /// Verifica se ocorrerá uma exceção do tipo NullReferenceException
        /// </summary>
        /// <param name="el"></param>
        private void TreatElementException(Elemento el)
        {
            Elemento aux;

            if (el == null)
            {
                throw new ArgumentNullException();
            }
            else if ((aux = GetElementOnList(el.GetDado())) == null)
            {
                throw new NullReferenceException();
            }
        }
コード例 #10
0
ファイル: Lista.cs プロジェクト: hkirschke/UNO-Game
 /// <summary>
 /// Remove o primeiro elemento da lista
 /// </summary>
 /// <returns></returns>
 public virtual T RemoveFirst()
 {
     if (this.prim.Prox != null)
     {
         Elemento aux  = this.prim.Prox;
         Elemento aux2 = aux;
         this.prim.Prox = aux.Prox;
         aux            = null;
         ElementDeleted();
         Rebuild();
         return((T)aux2.GetDado());
     }
     else
     {
         return(default(T));
     }
 }
コード例 #11
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());
        }
コード例 #12
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());
        }
コード例 #13
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));
        }
コード例 #14
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));
            }
        }