public static void Main(string[] args)
var first = new Node(10);
var second = new Node(15);
var third = new Node(12);
var fourth = new Node(13);
var fifth = new Node(20);
var sixth = new Node(14);
Console.WriteLine("=============== After swapping ===============");
static void Swap(ref Node head, int data1, int data2)
Node prev1 = null, prev2 = null, node1 = head, node2 = head;
while (node1 != null && node1.Data != data1)
while (node2 != null && node2.Data != data2)
if (node1 == null || node2 == null)
Console.WriteLine(node.Data);
public int GetLengthIterative()
public int GetLengthRecursive()
return 1 + this.Next.GetLengthRecursive();