#24

from utils.listNode import ListNode

class Solution:
    def swap_pairs(self, head):
        if not head:
            return None

        dummy = prev = ListNode(None)

        while head and head.next:
            next_head = head.next.next
            prev.next = head.next
            head.next.next = head
            prev = head
            head = next_head

        prev.next = head
    
        return dummy.next

one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)

one.next = two
two.next = three
three.next = four

print(one)

solution = Solution()
print(solution.swap_pairs(one))