public IEnumerator <T> GetEnumerator() { DoublyItem <T> current = head; while (current != null) { yield return(current.Data); current = current.Next; } }
/// <summary> /// Добавление элемента /// </summary> /// <param name="data"></param> public void Add() { var node = new DoublyItem <DoublyList <T> >(new DoublyList <T>()); if (head == null) { head = node; } else { tail.Next = node; node.Previous = tail; } tail = node; count++; }
/// <summary> /// Добавление элемента /// </summary> /// <param name="data"></param> public void Add(T data) { DoublyItem <T> node = new DoublyItem <T>(data); if (head == null) { head = node; } else { tail.Next = node; node.Previous = tail; } tail = node; count++; }
/// <summary> /// Удаление заданного элемента /// </summary> /// <param name="data"></param> /// <returns></returns> public bool Remove(int index) { if (index < 1 || index > count) { Console.WriteLine("Элемента с заданным индексом нет!"); return(false); } var current = head; for (var i = index - 1; i > 0; i--) { current = current.Next; } if (current != null) { if (current.Next != null) { current.Next.Previous = current.Previous; } else { tail = current.Previous; } if (current.Previous != null) { current.Previous.Next = current.Next; } else { head = current.Next; } count--; return(true); } return(false); }
/// <summary> /// Удаление заданного элемента /// </summary> /// <param name="data"></param> /// <returns></returns> public bool Remove(T data) { DoublyItem <T> current = head; while (current != null) { if (current.Data.Equals(data)) { break; } current = current.Next; } if (current != null) { if (current.Next != null) { current.Next.Previous = current.Previous; } else { tail = current.Previous; } if (current.Previous != null) { current.Previous.Next = current.Next; } else { head = current.Next; } count--; return(true); } return(false); }