Пример #1
0
        // Reverses the next N nodes in the list
        public static LinkedListNode <T> ReverseSection <T>(this LinkedListNode <T> current, int n)
        {
            var subset = new T[n];

            for (int i = 0; i < n; i++)
            {
                subset[i] = current.Value;

                if (i < n - 1)
                {
                    current = current.GetNextOrFirst();
                }
            }

            for (int i = 0; i < n; i++)
            {
                current.Value = subset[i];

                if (i < n - 1)
                {
                    current = current.GetPreviousOrLast();
                }
            }

            // Skip ahead forward to the next one
            return(current.Skip(n));
        }