Snippets Collections
class Solution
{
    public:
    Node* pairWiseSwap(struct Node* curr) 
    {
        // The task is to complete this method
        if(!curr || !curr->next)
            return curr;
        
        Node* nxtHead = pairWiseSwap(curr->next->next);
        Node* newHead = curr->next;
        curr->next->next = curr;
        curr->next = nxtHead;
        return newHead;
        
    }
};
star

Sat Oct 07 2023 04:12:38 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/pairwise-swap-elements-of-a-linked-list-by-swapping-data/1

#linkedlist #pairwiseswap

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension