title: Given a linked list, i & j, swap the nodes that are present at i & j position in the LL. You need to swap the entire nodes, not just the data
body: <p>I am getting this error: </p>
  
  <pre><code>Compilation Failed
  ./Solution.java:33: error: cannot find symbol
          while (node1 != null &amp;&amp; node1.val != i) {
                                       ^
    symbol:   variable val
    location: variable node1 of type LinkedListNode
  ./Solution.java:40: error: cannot find symbol
          while (node2 != null &amp;&amp; node2.val != j) {
                                       ^
    symbol:   variable val
    location: variable node2 of type LinkedListNode
  </code></pre>
  
  <p><strong>Expected Output</strong></p>
  
  <pre><code>3 4 5 6 2 1 9
  </code></pre>
  
  <hr>
  
  <pre><code>public class Solution {
  
  
  
  public static  LinkedListNode&lt;Integer&gt; swap_nodes(LinkedListNode&lt;Integer&gt; head,int i,int j){
          if (i == j)
              return head;
  
         LinkedListNode&lt;Integer&gt; prev1  = null, node1 = null, prev2 = null, node2 = null;
  
          //Search for the first node
          node1 = head;
          while (node1 != null &amp;&amp; node1.val != i) {
              prev1 = node1;
              node1 = node1.next;
          }
  
          //Search for the second node
          node2 = head;
          while (node2 != null &amp;&amp; node2.val != j) {
              prev2 = node2;
              node2 = node2.next;
          }
  
          if (node1 == null || node2 == null)
              return head;
  
          LinkedListNode&lt;Integer&gt;  tail1 = node1.next, tail2 = node2.next;
  
          if (node2 == node1.next) {
              if (prev1 != null)
                  prev1.next = node2;
              node2.next = node1;
              node1.next = tail2;
          }
          else if(node1 == node2.next) {
              if (prev2 != null)
                  prev2.next = node1;
              node1.next = node2;
              node2.next = tail1;
          }
          else {
              if (prev1 != null)
                  prev1.next = node2;
              node2.next = tail1;
              if (prev2 != null)
                  prev2.next = node1;
              node1.next = tail2;
          }
  
          if (node1 == head)
              head = node2;
          else if (node2 == head)
              head = node1;
  
          return head;
      }
  }
  </code></pre>