For a long time it puzzled me how something so expensive, so leading edge, could be so useless. And then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. Bill Bryson

Pairwise swap elements

Language Java | Level Intermediate | Category Data structure | September 5, 2015 10:44 pm


Data structure Description

Write a program to swap alternative nodes in the singly linked list. Linked list node contains data and link to the next node. The utility function takes the linked list head node and returns the swapped linked list head node. The display function iterate all the nodes and display the values.

Ex 1->2->3-4>5 it should swap 2->1->3-4>5.


Output

   					 

Print the list of items: 21->52->33->21->67->NULL
Print the list of items after pairwise Swap: 52->21->21->33->67->NULL

				    

Comments


No comments available!

Please login to add comments.