public void AddBefore(T value, T addValue) { NodeDouble <T> current = Head; while (current != null) { if (current.Value.Equals(value)) { NodeDouble <T> previos = current.Previos; if (previos == null) { Head = new NodeDouble <T>(addValue); Head.Next = current; current.Previos = Head; } else { previos.Next = new NodeDouble <T>(addValue); previos.Next.Next = current; previos.Next.Previos = previos; current.Previos = previos.Next; } Count++; return; } current = current.Next; } }
public void AddAfter(T value, T addValue) { NodeDouble <T> current = Head; while (current != null) { if (current.Value.Equals(value)) { NodeDouble <T> temp = current.Next; current.Next = new NodeDouble <T>(addValue); current.Next.Previos = current; if (temp != null) { current.Next.Next = temp; } else { Tail = current.Next; } Count++; return; } current = current.Next; } }
public IEnumerator <T> GetEnumerator() { NodeDouble <T> current = Head; while (current != null) { yield return(current.Value); current = current.Next; } }
public void AddFirst(T value) { NodeDouble <T> node = new NodeDouble <T>(value); if (Head != null) { Head.Previos = node; node.Next = Head; } Head = node; Count++; Tail = Tail ?? Head; //if (tail == null) tail = head; }
public T[] CopyToArray() { T[] arr = new T[Count]; NodeDouble <T> current = Head; int counter = 0; while (current != null) { arr[counter] = current.Value; counter++; current = current.Next; } return(arr); }
public bool Contains(T value) { NodeDouble <T> current = Head; while (current != null) { if (current.Value.Equals(value)) { return(true); } current = current.Next; } return(false); }
public void AddFirst(T value) { if (Count == 0) { Tail = Head = new NodeDouble <T>(value); } else if (Count > 0) { NodeDouble <T> temp = new NodeDouble <T>(value); temp.Next = Head; Head.Previos = temp; Head = Head.Previos; } Count++; }
public void AddLast(T value) { NodeDouble <T> node = new NodeDouble <T>(value); if (Head == null) { Head = Tail = node; } else { Tail.Next = node; node.Previos = Tail; Tail = node; } Count++; }
public void RemoveLast() { if (Tail != null) { if (Tail.Previos == null) { Clear(); } else { Tail.Previos.Next = null; Tail = Tail.Previos; Count--; } } }
public void AddLast(T value) { if (Count == 0) { Tail = Head = new NodeDouble <T>(value); } else if (Count > 0) { NodeDouble <T> temp = new NodeDouble <T>(value); Tail.Next = temp; temp.Previos = Tail; Tail = Tail.Next; } Count++; }
public T GetFirst() { if (Count > 1) { T value = Head.Value; Head = Head.Next; Head.Previos = null; Count--; return(value); } else if (Count == 1) { T value = Tail.Value; Tail = Head = null; Count--; return(value); } else { throw new IndexOutOfRangeException("Deck is empty"); } }
public bool Remove(T value) { NodeDouble <T> current = Head; while (current != null) { if (current.Value.Equals(value)) { if (current.Previos == null) { Head = current.Next; if (Head != null) { Head.Previos = null; } else { Tail = null; } } else if (current.Next == null) { Tail = current.Previos; Tail.Next = null; } else { current.Previos.Next = current.Next; current.Next.Previos = current.Previos; } Count--; return(true); } current = current.Next; } return(false); }
public void Clear() { Head = Tail = null; Count = 0; }
public void Clear() { Tail = Head = null; Count = 0; }