# Swap Node In Pairs Problem Solution

Swap Node In Pairs: Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.)

Example:

```Input: head = [1,2,3,4]
Output: [2,1,4,3]```

## Problem Solution In Python

``````def swapPairs(self, head: ListNode) -> ListNode:
return h
``````

## Problem Solution In Java

``````public ListNode swapPairs(ListNode head) {
ListNode n = helper(head);
return n;
}

public ListNode helper(ListNode head) {
if (head == null || head.next == null) {
}

ListNode tmp = head;
ListNode next = head.next;

next.next = tmp;
return next;
}
``````

## Problem Solution In C++

``````void _swapPairs(ListNode* odd, ListNode* even, ListNode** prev) {
if (!odd || !even) return;
*prev = even;
ListNode* temp = even->next;
even->next = odd;
odd->next = temp;
_swapPairs(odd->next, odd->next ? odd->next->next: NULL, &odd->next);
}
ListNode* swapPairs(ListNode* head) {
}
``````

## Problem Solution In C

``````struct ListNode* swapPairs(struct ListNode* head) {
typedef struct ListNode Node;
Node *root  = head;
Node *prev = NULL;
int temp;
int count = 0;
if(count %2 == 1){
temp = prev->val;