title: Delete the node before the given node
body: <p>I have the code to delete a specific node but I cannot delete the node before a given node. Any ideas on how to do it with this function? (Solution below)</p>
  
  <pre><code>void deleBefore(Node q) {
      if (q == null || q == head) {
          return;
      }
  
      Node p = null;
      Node n = head;
      while (n != null &amp;&amp; n.next != q) {
          p = n;
          n = n.next;
      }
      if (n == null) {
          return;
      }
  
      if (n == head) {
          head = q;
      } else {
          p.next = q;
      }
  </code></pre>
  
  <p>Node class</p>
  
  <pre><code>public class Node {
  
  Boat info;
  Node next;
  
  Node() {
  }
  
  Node(Boat x, Node p) {
      info = x;
      next = p;
  }
  
  Node(Boat x) {
      this(x, null);
  }
  </code></pre>
  
  <p>}</p>