public Nod Reverse(Nod ptr) { Nod temp; Nod previous = null; while (ptr != null) { temp = ptr.next; ptr.next = previous; previous = ptr; ptr = temp; } return previous; }
public int Check(Nod a, Nod b) { int count = 0; Nod ptr1 = a, ptr2 = b; while (ptr1 != null && ptr2 != null) { if (ptr1.data == ptr2.data) { count++; ptr2 = ptr2.next; } else { ptr2 = b; count = 0; } ptr1 = ptr1.next; } return count; }
void Swap(Nod root, int k) { Nod ptr1 = root, ptr2 = root, ptr3 = root; int count = 0; while (ptr3 != null) { count++; if (count == k-1) { ptr1 = ptr3; ptr2 = root; } else if (count > k) { ptr2 = ptr2.next; } ptr3 = ptr3.next; } Nod temp = ptr1.next; ptr1.next = ptr2.next; ptr2.next = temp; }