/// <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> /// 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); }
/// <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; } }
/// <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)); } }
/// <summary> /// Limpa a pilha /// </summary> public void Clear() { this.topo = this.fundo = null; }
public Pilha() { this.topo = new Elemento(null); this.fundo = this.topo; }
public Lista() { this.prim = new Elemento(null); this.ult = this.prim; }