public static Node Assamble(Node list, int n) { Node p1 = list; Node p2 = null; var count = 1; if (p1.Next != null) { p2 = p1.Next; } while (p2.Next != null) { p2 = p2.Next; count++; if (count > n) { p1 = p1.Next; count--; } } p2.Next = list; var root = p1.Next; p1.Next = null; return root; }
static void Main(string[] args) { var list = new Node { Value = 1, Next = new Node { Value = 2, Next = new Node { Value = 3, Next = new Node { Value = 4, Next = new Node { Value = 5, Next = new Node { Value = 6, Next = null } } } } } }; var result = AssembleList.Assamble(list, 2); var root = result; while (root != null) { Console.Write(root.Value + " -> "); root = root.Next; } Console.ReadKey(); }