using System.Collections.Generic;
public static Node SwapPairs(Node head)
public static void Main(string[] args)
Console.WriteLine("\nTesting odd input...");
Console.WriteLine("\nTesting even input...");
Console.WriteLine("\nTesting small input...");
Console.WriteLine("\nTesting null input...");
public static void TestOddInput()
Node head = Node.CreateList(5);
Console.WriteLine("Input: " + head);
Console.WriteLine("Output: " + head);
public static void TestEvenInput()
Node head = Node.CreateList(6);
Console.WriteLine("Input: " + head);
Console.WriteLine("Output: " + head);
public static void TestSmallInput()
Console.WriteLine("Input: " + head);
Console.WriteLine("Output: " + head);
public static void TestNullInput()
Console.WriteLine("Input: null");
Node head = SwapPairs(null);
Console.WriteLine("Output: " + (head != null? head.ToString(): "null"));
public Node Next { get; set; }
public int Data { get; private set; }
public static Node CreateList(int count)
List<Node> nodes = Enumerable.Range(1, count).Select(i => new Node(i)).ToList();
for (int i = 0; i < nodes.Count - 1; i++)
nodes[i].Next = nodes[i + 1];
public override string ToString()
return string.Format("({0}) -> {1}", Data, Next);
return string.Format("({0}) -> null", Data);