java jdk doubly linked list code example
Example: double linked list java
class doublelinkedlist{
Node head;
Node tail;
static class Node{
int data;
Node previous;
Node next;
Node(int data) { this.data = data; }
}
public void addLink(int data) {
Node node = new Node(data);
if(head == null) {
head = tail = node;
head.previous = null;
} else {
tail.next = node;
node.previous = tail;
tail = node;
}
tail.next = null;
}
}