# JAVA Program to Delete a Node from the Nth Position of a Doubly Linked Last

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

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. ## 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. ## Algorithm to be used for the Deletion of a Node from a Specific Index of a Doubly Linked List

• RETURN
• ELSE
• INT POS =N;
• FOR(INT I = 1; I < POS; I++)
• CURRENT = 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

```   public class PrepInsta
{
class Node{
int data;
Node prev;
Node next;
public Node(int data) {
this.data = data;
}
}
public void display() {
while (temp != null) {
System.out.print(temp.data + "–>");
temp = temp.next;
}
System.out.println("END");
}
Node newNode = new Node(data);
tail.next = null;
}
else {
tail.next = newNode;
newNode.prev = tail;
tail = newNode;
tail.next = null;
}
}
public void deletenth(int n) {
return;
}
else {

int pos =n;

for(int i = 1; i < pos; i++){
current = current.next;
}

}
else if(current == tail) {
tail = tail.prev;
}
else {
current.prev.next = current.next;
current.next.prev = current.prev;
}
current = null;
}
}
void print() {
System.out.println("List is empty");
return;
}
while(curr != null)
{
System.out.print(curr.data + " ");
curr = curr.next;
}
System.out.println();
}
public static void main(String[] args) {
PrepInsta dList = new PrepInsta();
```Initial Doubly Linked List: