/// <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)); }
/// <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()); }
/// <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()); }
/// <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)); } }
/// <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)); } }
/// <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()); }
/// <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); }
/// <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); }
/// <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(); } }
/// <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)); } }
/// <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()); }
/// <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()); }
/// <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)); }
/// <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)); } }