public CircularList <T> Extract(int n)
        {
            if (n <= 0)
            {
                throw new ApplicationException();
            }

            var last = this;

            while (--n > 0)
            {
                if (last.Next == this)
                {
                    break;
                }
                last = last.Next;
            }

            Previous.Next      = last.Next;
            last.Next.Previous = Previous;

            Previous  = last;
            last.Next = this;

            return(this);
        }
        public void Insert(CircularList <T> chain)
        {
            var oldNext          = Next;
            var oldChainPrevious = chain.Previous;

            Next = chain;
            chain.Previous.Next = oldNext;
            chain.Previous      = this;
            oldNext.Previous    = oldChainPrevious;
        }
        public void Add(T value)
        {
            var newNode = new CircularList <T>(value)
            {
                Next     = this,
                Previous = Previous
            };

            Previous.Next = newNode;
            Previous      = newNode;
        }
        public static CircularList <T> From(IEnumerable <T> enumerableItems)
        {
            var items = enumerableItems.ToList();

            if (!items.Any())
            {
                throw new ApplicationException("CircularList cannot be empty");
            }
            var first = new CircularList <T>(items.First());

            foreach (var item in items.Skip(1))
            {
                first.Add(item);
            }
            return(first);
        }
 private CircularList(T value)
 {
     Value    = value;
     Next     = this;
     Previous = this;
 }