public void deleteFromEnd() {
            if(head == null) {  
              return;  
            }  
            else {  
              if(head != tail ) {  
                Node current = head;  
                while(current.next != tail) {  
                    current = current.next;  
                }  
                tail = current;  
                tail.next = null;  
              }  
              else {  
                head = tail = null;  
              }  
            }  
        }  

      Java language logo
      Delete Node from end in linked list

      Axt

      This code deletes the nodes in the list in order from the front to the back. If the head node is null, the code returns immediately. Otherwise, the code checks to see if the head node is less than or equal to the tail node. If it is, then the code updates the head and the tail nodes, and then it exits. If the head is not less than the tail, then the code updates the head and tail nodes, and then it exits.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.