Swap every two nodes in a single linked list


Write code to swap every two nodes in a single linked list. Example: Input: 2 -> 3 -> 31 -> 21 -> 5 Output: 3 -> 2 -> 21 -> 31 -> 5 public class Answer implements SwapEveryTwoNodesInLinkedListInterface{ @Override public Node SwapEveryTwoNodesInLinkedList(Node head) { // WRTIE YOUR CODE HERE return ; } } // Here is the Node.java public class Node { public int nodeValue; public Node nextNode; }

Answer

No comments:

Post a Comment