public void InsertAfter(T item, List <T> elements) { RingElement <T> cur = Index[item]; foreach (T value in elements) { RingElement <T> element = new RingElement <T>(value); Index[value] = element; element.Next = cur.Next; cur.Next = element; cur = element; } }
public List <T> RemoveAfter(T item, int count) { List <T> res = new List <T>(); RingElement <T> cur = Index[item]; while (res.Count < count) { T value = cur.Next.Value; res.Add(value); cur.Next = cur.Next.Next; Index.Remove(value); } return(res); }
public FastRing(IEnumerable <T> input) { Index = new Dictionary <T, RingElement <T> >(); RingElement <T> firstElement = null; RingElement <T> lastElement = null; foreach (T item in input) { RingElement <T> element = new RingElement <T>(item); Index[item] = element; if (firstElement == null) { firstElement = element; } if (lastElement != null) { lastElement.Next = element; } lastElement = element; } lastElement.Next = firstElement; }
public RingElement(T value) { Value = value; Next = null; }