# Implement Queue by Linked List II

ID: 493; easy

## Solution 1 (Java)

``````class Node {
public int val;
public Node prev, next;
public Node(int val) {
this.val = val;
prev = next = null;
}
}

public class Dequeue {

private Node head, tail;

public Dequeue() {
head = tail = null;
}

/*
* @param item: An integer
* @return: nothing
*/
public void push_front(int item) {
if (head == null) {
head = new Node(item);
} else {
Node newNode = new Node(item);
}
}

/*
* @param item: An integer
* @return: nothing
*/
public void push_back(int item) {
if (tail == null) {
tail = new Node(item);
} else {
Node newNode = new Node(item);
newNode.prev = tail;
tail.next = newNode;
tail = newNode;
}
}

/*
* @return: An integer
*/
public int pop_front() {
if (head != null) {
int item = head.val;
if (head != null) {
} else {
tail = null;
}
return item;
}
return -1;
}

/*
* @return: An integer
*/
public int pop_back() {
if (tail != null) {
int item = tail.val;
tail = tail.prev;
if (tail != null) {
tail.next = null;
} else {