Write an algorithm to delete a node at end of the doubly linked list and create the logic for the same
public class Main {
Node head;
Node tail;
public void deleteTail() {
if (tail != null) {
if (tail.prev == null) {
head = null;
tail = null;
} else {
tail = tail.prev;
tail.next = null;
}
}
}
static class Node {
Node next;
Node prev;
int data;
public Node(int data) {
this.data = data;
}
}
}
Comments
Leave a comment