自定义LinkedList实现

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);http://www.huiyi8.com/jiaoben/ 网页特效代码
     * 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);
     * 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值