JAVA Program for Deletion from Nth Position of a Doubly Linked List

JAVA Program to Delete a Node from the Nth Position

In this page we’ll take a look at a comprehensive explanation of Deleting a Node from a specific index of a Doubly Linked List, one of the most widely used operation on a Doubly Linked List

deletion in doubly linked list

Steps to be followed while Deleting a Node from the Nth Position of a Doubly Linked List

  • Check for the presence of Node in the List, if there exists some Nodes, Continue.
  • Now, to delete a node from Nth position of the Doubly Linked List, we’ll have to delete and redirect various links of the Linked List.
  • First of all the next pointer of the (n-1)th Node of the Linked List will now point to the address of the (n+1)th node of the Doubly Linked List.
  • Now the Previous Pointer of the (n+1)th Node of the Linked List will now be re-directed to the address of (n-1)th node of the List.

Example:

If we have a list (10 –> 20 –> 30 –> 40 –> 50) and we have to delete a node on the Second Index of the List, that is i=2, then after deleting a node. Updated Linked list will be (10 –> 20 –> 40 –> 50) . We will be learning more about the whole process in the explanation below.

Deletion from Nth position in a doubly linked list

Algorithm to be used for the Deletion of a Node from a Specific Index of a Doubly Linked List

  •  IF(HEAD == NULL)
    • RETURN
  • ELSE
    • NODE CURRENT = HEAD;
    • INT POS =N;
  • FOR(INT I = 1; I < POS; I++)
    • CURRENT = CURRENT.NEXT
  • IF(CURRENT == HEAD)
    • HEAD = CURRENT.NEXT
  • ELSE IF(CURRENT == TAIL)
    • TAIL = TAIL.PREV
  • ELSE
    • CURRENT.PREV.NEXT = CURRENT.NEXT
    • CURRENT.NEXT.PREV = CURRENT.PREV
  • CURRENT = NULL

Java Program for Deletion from the Nth Position of a Doubly Linked List

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

Doubly Linked List

  • Introduction to Doubly Linked list in Data Structure
    Click Here
  • Doubly Linked List in –
    C | C++ | Java
  • Insertion in doubly linked list –
    C | C++ | Java
  • Insertion at beginning in doubly linked list –
    C | C++ | Java
  • Insertion at end in doubly linked list –
    C | C++ | Java
  • Insertion at nth node in doubly linked list –
    C | C++ | Java
  • Deletion in doubly linked list  –
    C | C++ | Java
  • Deletion from beginning in doubly linked list :
  • Deletion from nth in doubly linked list :
    C | C++ | Java
  • Deletion from end in doubly linked list :
    C | C++ | Java
  • Insertion and Deletion in a  doubly linked list :
    C | C++ | Java
  • Insertion in the middle in a  doubly linked list :
    C | C++ | Java

Doubly Linked List