码迷,mamicode.com
首页 > 其他好文 > 详细

自定义LinkedList实现

时间:2014-07-02 17:07:48      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:http   os   cti   代码   for   io   

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/ JQuery特效
* 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

自定义LinkedList实现,布布扣,bubuko.com

自定义LinkedList实现

标签:http   os   cti   代码   for   io   

原文地址:http://www.cnblogs.com/cjings/p/3819982.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!