Posts

Showing posts from June, 2018

Pairwise swap of a given linked list by changing links

Image
Input:  1->->2->3->4->5 Output: 2->1->4->3->5 Code: package linkedlist; public class Swaplinks {     Node head = null;     void swap(){                Node prev = head;         Node curr = head.next;         head = curr;                while(true){                        Node temp = curr.next;             curr.next = prev;                        //for last node or null node             if(temp == null || temp.next == null){            ...