博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义LinkedList实现
阅读量:4490 次
发布时间:2019-06-08

本文共 3212 字,大约阅读时间需要 10 分钟。

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/ 
* 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

转载于:https://www.cnblogs.com/cjings/p/3819982.html

你可能感兴趣的文章
学习进度条
查看>>
Linux crontab 定时任务详解
查看>>
string成员函数
查看>>
onSaveInstanceState()方法问题
查看>>
[转]CocoaChina上一位工程师整理的开发经验(非常nice)
查看>>
大数据时代侦查机制有哪些改变
查看>>
L1-047 装睡
查看>>
雷林鹏分享:jQuery EasyUI 菜单与按钮 - 创建链接按钮
查看>>
Apache Traffic Server服务搭建
查看>>
poj1990两个树状数组
查看>>
学习python-day1
查看>>
Zend_Db_Table->insert ()和zend_db_adapter::insert方法返回值不同
查看>>
递归问题
查看>>
Hyperledger下子项目
查看>>
Linq-查询上一条下一条
查看>>
常见前端开发的题目,可能对你有用
查看>>
BeautifulSoap库入门
查看>>
乐观锁与悲观锁
查看>>
Codeforces Round #328 (Div. 2)D. Super M 虚树直径
查看>>
Java判断是否为移动端
查看>>