@@ -0,0 +1,1346 @@
+package geeksforgeeks;%0D%0A%0D%0Aimport ctci._02linkedList;%0D%0Aimport ctci._02linkedList.Node;%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A/*%0D%0A * http://www.geeksforgeeks.org/amazon-interview-set-33-2/%0D%0A * Given a singly linked list, swap every 2 nodes,%0D%0A * for odd number of input; retain the last node as it is.%0D%0A * Eg: Input: 5 13 15 18 20 11 6 7%0D%0A * Output: 13 5 18 15 11 20 7 6%0D%0A */;%0D%0A public class _01AmazonInterview_33_01 %7B%0D%0A%09 public static void main(String%5B%5D args) %7B%0D%0A%09%09 _02linkedList linkedList=new _02linkedList();%0D%0A%09%09 linkedList.add(5);%0D%0A%09%09 linkedList.add(13);%0D%0A%09%09 linkedList.add(15);%0D%0A%09%09 linkedList.add(18);%0D%0A%09%09 linkedList.add(20);%0D%0A%09%09 linkedList.add(11);%0D%0A%09%09 linkedList.add(6);%0D%0A%09%09 linkedList.add(7);%0D%0A%09%09 System.out.println(linkedList.toString());%09%09 %0D%0A%09%09 linkedList=swapTwoNodes(linkedList);%0D%0A%09%09 System.out.println(linkedList.toString());%0D%0A%09 %7D%0D%0A%0D%0A%09private static _02linkedList swapTwoNodes(_02linkedList linkedList) %7B%0D%0A%09%09Node pointerNode=linkedList.getHeadNode();%0D%0A%09%09while(pointerNode!=null && pointerNode.next!=null)%0D%0A%09%09%7B%0D%0A%09%09%09pointerNode.data=pointerNode.data%5EpointerNode.next.data;%0D%0A%09%09%09pointerNode.next.data=pointerNode.data%5EpointerNode.next.data;%0D%0A%09%09%09pointerNode.data=pointerNode.data%5EpointerNode.next.data;%0D%0A%09%09%09if(pointerNode.next!=null && pointerNode.next.next!=null)%0D%0A%09%09%09%09pointerNode=pointerNode.next.next;%0D%0A%09%09%09else%0D%0A%09%09%09%09break;%0D%0A%09%09%09%0D%0A%09%09%7D%0D%0A%09%09return linkedList;%0D%0A%09%7D%0D%0A%0D%0A%0D%0A %7D

swap 2 nodes completed