title: Delete a last node of linked list given pointer to that node
body: <p>I'm trying to delete the last node of the linkedlist, given pointer only to that node.   </p>
  
  <p>I wrote the below implementation, but isn't working.</p>
  
  <p>I already visited majority of SO questions regarding this subject, but none of them shows how to delete last node of linked list, if there's only one pointer to that node ?</p>
  
  <p>Am I missing anything here ?</p>
  
  <pre><code>class Node {
  
          Node next;
          int value;
  
          Node(int val) {
                  this.value = val;
                  this.next = null;
          }
  
          @Override
          public String toString() {
                  Node cur = this;
                  String str = "";
  
                  while(cur != null) {
                          str += cur.value+"-&gt;";
                          cur = cur.next;
                  }
  
                  return str;
          }
  }
  
  class DeleteNodeLL {
  
      public static void deleteNode(Node current) {
          Node temp;
          if(current.next == null) {
              current = null;
              return;
          } else {
              current.value = current.next.value;
              temp = current.next;
              temp = null;
              current.next = current.next.next;
          }
  
      }
      public static void main(String [] args) {
  
          Node n1 = new Node(25);
          Node n2 = new Node(1);
          Node n3 = new Node(36);
          Node n4 = new Node(9);
          Node n5 = new Node(14);
  
          n1.next = n2;
          n2.next = n3;
          n3.next = n4;
          n4.next = n5;
          n5.next = null;
  
          System.out.println("Original linkedlist :");
          System.out.println(n1);
  
          System.out.println();
  
          System.out.println("After deleting a node :");
          deleteNode(n5);
          System.out.println(n1);
      }
  }
  </code></pre>
  
  <p>Output :-</p>
  
  <blockquote>
    <p>Original linkedlist :<br>
    25->1->36->9->14-></p>
    
    <p>After deleting a node :<br>
    25->1->36->9->14-></p>
  </blockquote>