public void Delete(T data) { DuplexPoint <T> current = Head; while (current != null) { if (current.Data.Equals(data)) { if (Head.Previous != null) { current.Previous.Next = current.Next; current.Next.Previous = current.Previous; Count--; return; } else { Head = current.Next; Head.Previous = null; Count--; return; } } current = current.Next; } Console.WriteLine("Элемент не найден!"); }
public void Add(T data) { DuplexPoint <T> item = new DuplexPoint <T>(data); if (Count == 0) { SetHeadAndTail(item); } else { Tail.Next = item; item.Previous = Tail; Tail = item; Count++; } }
public void DeleteEven() { DuplexPoint <T> current = Head; int check = 1; if (current == null) { Console.WriteLine("Список пуст!"); } while (current != null) { if (check % 2 == 0) { current.Previous.Next = current.Next; current.Next.Previous = current.Previous; Count--; } check++; current = current.Next; } Console.WriteLine("Элементы были удалены!"); return; }
public DuplexPoint(T data) { Data = data; Next = null; Previous = null; }
public DuplexPoint() { Next = null; Previous = null; Data = default(T); }
private void SetHeadAndTail(DuplexPoint <T> item) { Head = item; Tail = item; Count = 1; }
public LinkedList(T data) { DuplexPoint <T> item = new DuplexPoint <T>(data); SetHeadAndTail(item); }