Swap Nodes in Pairs
C
1struct ListNode* swapPairs(struct ListNode* head) {
2 if (head == NULL || head->next == NULL){
3 return head;
4 }
5 struct ListNode * temp = head;
6 int num_to_swap;
7 while(temp != NULL){
8 if(temp->next == NULL){
9 break;
10 }
11 num_to_swap = temp->val;
12 temp->val = temp->next->val;
13 temp->next->val = num_to_swap;
14 temp = temp->next->next;
15 }
16 return head;
17}