//Метод удаления элемента из списка 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("Элемент не найден!"); }
//Обычный метод подсчета элементов в листе static int Count(DuplexPoint <int> point, int count) { count++; while (point.Next != null) { count++; point = point.Next; } return(count); }
//Рекурсивный метод подсчета элементов в листе static int CountRec(DuplexPoint <int> point, int count) { count++; if (point.Next == null) { return(count); } return(CountRec(point.Next, count)); }
//Метод добавления элемента в список 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 LinkedList(T data) { DuplexPoint <T> item = new DuplexPoint <T>(data); SetHeadAndTail(item); }
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; }