1class doublelinkedlist{
2 Node head;
3 Node tail;
4
5 static class Node{
6 int data;
7 Node previous;
8 Node next;
9
10 Node(int data) { this.data = data; }
11 }
12
13 public void addLink(int data) {
14 Node node = new Node(data);
15
16 if(head == null) {
17 head = tail = node;
18 head.previous = null;
19 } else {
20 tail.next = node;
21 node.previous = tail;
22 tail = node;
23 }
24 tail.next = null;
25 }
26}