LinkedList is a linear data structure which allows to insert and remove elements at the front and rear in constant time.

LinkedLists are typically of two types,

Each node has a reference to the next node.
Each node has a reference to previous and next nodes.

Doubly Linked Lists are used extensively in various computer science domains like caching, binary trees etc.

###### Node Structure

A Single Linkedlist typically has a node reference to the next node and a value, on the other hand the doubly linked list has two references, previous and next, pointing to different nodes.

``````class DNode{
DNode prev, next;
T val;
}
``````
###### List Operations

The doubly linked list allows typical operations like adding or removing elements to the lists, search ane element in the list.

###### Implementation
``````package src.DSFullImplementations;
/*
* Author: Venkatesh Thallam
*
*/

/*
* Node definition with two pointers
*/
class DNode {
DNode prev, next;
int val;

DNode(int val) {
this.val = val;
prev = next = null;
}
}

/*
* Head points to the first element of the list and tail to the last
*/

}

public static void main(String[] args) {
list.print();
System.out.println("List size is " + list.size());
list.remove(30);
list.print();
list.remove(20);
list.print();
}

/*
* Adds an element after certain element. If ele is null, it inserts at the
* front
*/
public void add(int val, Integer ele) {
/*
* If target node is head
*/
head = tail = new DNode(val);
} else if (head.val == ele || ele == null) {
DNode temp = new DNode(val);
}
/*
* If target node is tail
*/
else if (tail.val == ele) {
DNode newnode = new DNode(val);
tail.next = newnode;
newnode.prev = tail;
tail = newnode;
} else {
DNode newnode = new DNode(val);
while (temp.next != null && temp.val != ele) {
temp = temp.next;
}
newnode.next = temp.next;
newnode.prev = temp;
temp.next = newnode;
}
}

/*
* Removes the specified element
*/
public void remove(int ele) {
/*
* If target node is head
*/
}
/*
* If target node is tail
*/
else if (tail.val == ele) {
tail = tail.prev;
tail.next = null;
} else {
while (temp.next != null && temp.next.val != ele) {
temp = temp.next;
}
if (temp != null) {
temp.next = temp.next.next;
temp.next.prev = temp;
}
}
}

/*
* Checks whether a certain element is true
*/
public boolean search(int ele) {
while (temp != null) {
if (temp.val == ele) {
return true;
}
temp = temp.next;
}
return false;
}

/*
* Returns the number of elements in the linked list.
*/
public int size() {
int count = 0;
while (temp != null) {
count++;
temp = temp.next;
}
return count;
}

/*
* Prints the elements in the list
*/
public void print() {