1. [代码]首先是借口定义     

 * @author xzf

public interface MyDeque<E> {

     * insert the specified element at the front of this deque if it is possible

     * to do so immediately without violating capacity restrictions.

@param e the element to add

    void addFirst(E e);

     * insert the specified element at the end of this deque if it is possible

     * to do so immediately without violating capacity restrictions.

     * @param e the element to add

    void addLast(E e);

     * @return the head of this deque

    E removeFirst();

     * @return the tail of this deque

    E removeLast();

     * insert the specified element into the queue represented by this deque

* (in other words, at the tail of this deque) if it is possible

     * to do so immediately without violating capacity restrictions.

     * @return true upon success

    boolean add(E e);

     * retrieve and remove the head of this queue represented by this deque

     * (in other words, the first element of this deque).

     * @return the head of the queue represented by this deque

     * push an element onto the stack represented by this deque

     * (in other words, at the head of this deque) if it is possible

to do so immediately without violating capacity restrictions.

     * @param e the element to push

    void push(E e);

     * pop an element from the stack represented by this deque. In other words,

     * removes and returns the first element of this deque.

     * @return the element at the front of this deque

     * return the number of elements of this dceque.

     * @return the number of elements of this dceque

2. [代码]自定义LinkedList实现类     

view sourceprint?

 * @author xzf

 * @param <E>

public class MyLinkedList<E> implements MyDeque<E>{

    private Entry<E> header;

    private int size;

    public MyLinkedList()

        header = new Entry<E>(null, null, null);

        size = 0;

        header.next = header.privious = header;

     * insert the specified element at the front of this deque if it is possible

     * to do so immediately without violating capacity restrictions.

     * @param e the element to add

    public void addFirst(E e) {

        addBefore(e, header.next);

     * insert the specified element at the end of this deque if it is possible

     * to do so immediately without violating capacity restrictions.

 @param e the element to add

    public void addLast(E e) {

        addBefore(e, header);

     * retrieve and remove the first element of this deque.

     * @return the head of this deque

    public E removeFirst() {

        return remove(header.next);

     * @return the tail of this deque

    public E removeLast() {

        return remove(header.privious);

     * insert the specified element into the queue represented by this deque

     * (in other words, at the tail of this deque) if it is possible

     * to do so immediately without violating capacity restrictions.

     * @return true upon success

    public boolean add(E e) {

        addBefore(e, header);http://www.huiyi8.com/jiaoben/ javascript特效

     * retrieve and remove the head of this queue represented by this deque

     * (in other words, the first element of this deque).

     * @return the head of the queue represented by this deque

    public E remove() {

        return removeFirst();

     * push an element onto the stack represented by this deque

     * (in other words, at the head of this deque) if it is possible

     * to do so immediately without violating capacity restrictions.

     * @param e the element to push