예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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;
        }
예제 #4
0
 public RingElement(T value)
 {
     Value = value;
     Next  = null;
 }