using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LinkedList { class List { private Link _head; private Link _tail; public List() { _head = new Link(null); _tail = _head; } public void Append(Product product) { Link link = new Link(product); _tail.Append(link); _tail = link; } public void Insert(Product product) { if (_head.Next != null) Insert(_head.Next, product); else Append(product); } public void Insert(Link link, Product product) { link.Insert(new Link(product)); } public void Remove(Product product) { Link found = Find(product); if(found != null) { if (found == _tail) _tail = found.Prev; found.Unlink(); } } public Link Find(Product product) { Link next = _head.Next; while(next != null) { if (next.Product == product) return next; next = next.Next; } return null; } public void Display() { Link next = _head.Next; int i = 0; if (next == null) { Console.WriteLine("Empty list"); return; } while (next != null) { Console.WriteLine("{0}: {1}", i++, next.Product.Name); next = next.Next; } } } }