IEnumerator <T> IEnumerable <T> .GetEnumerator() { DoublyNode <T> current = head; do { if (current != null) { yield return(current.Data); current = current.Next; } } while (current != head); }
public void Add(T data) { DoublyNode <T> node = new DoublyNode <T>(data); if (head == null) { head = node; head.Next = node; head.Previous = node; } else { node.Previous = head.Previous; node.Next = head; head.Previous.Next = node; head.Previous = node; } count++; }
public bool Contains(T data) { DoublyNode <T> current = head; if (current == null) { return(false); } do { if (current.Data.Equals(data)) { return(true); } current = current.Next; } while (current != head); return(false); }
public bool Remove(T data) { DoublyNode <T> current = head; DoublyNode <T> removedItem = null; if (count == 0) { return(false); } do { if (current.Data.Equals(data)) { removedItem = current; break; } current = current.Next; }while (current != head); if (removedItem != null) { if (count == 1) { head = null; } else { if (removedItem == head) { head = head.Next; } removedItem.Previous.Next = removedItem.Next; removedItem.Next.Previous = removedItem.Previous; } count--; return(true); } return(false); }
public void Clear() { head = null; count = 0; }