Pairwise swap elements of a linked list by swapping data
Submissions: 18028   Accuracy:


  Difficulty: Easy   Marks: 2

Given a singly linked list, write a function to swap elements pairwise. For example, if the linked list is 1->2->3->4->5 then the function should change it to 2->1->4->3->5, and if the linked list is 1->2->3->4->5->6 then the function should change it to 2->1->4->3->6->5.


In this problem, method takes one argument: the head of the linked list. The function should not read any input from stdin/console.
The struct Node has a data part which stores the data and a next pointer which points to the next element of the linked list. 
There are multiple test cases. For each test case, this method will be called individually.

Pairwise swap linked list elements .

Note: If you use "Test" or "Expected Output Button" use below example format

1 2 2 4 5 6 7 8

2 1 4 2 6 5 8 7

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Karan Grover

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.