自定义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);
* 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

时间: 2024-10-10 06:47:46

自定义LinkedList实现的相关文章

自定义Java集合

一.泛型 1.在JDK1.4以前,所有的集合元素全都按照Object来存储,拿出来还要进行强制转型.由于这样的做法有太多的缺点,容易出现ClassCaseException,不安全,让人不省心,于是乎JDK5之后出现了泛型. 2.什么是泛型,通俗的讲,就是在Java文件编译期对类型进行检查.比如:List<String> string = new ArrayList<String>(); 它只能装String类型的对象,否则编译时报错. 二.自定义ArrayList 1.Array

Java - Collection

http://blog.csdn.net/itlwc/article/details/10148321 Java - Collection 2013-08-21 15:13 4389人阅读 评论(3) 收藏 举报  分类: JavaSE(30)  版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Collection层次结构 Collection [plain] view plain copy 子接口 Set,List 集合中只能放置对象的引用,不能放置原生数据类型, 我们

java开始到熟悉103-104

本次内容:linkedlist() 此次是承接上次arraylist(),自己实现linkedlist()(内容较少) 1 package list; 2 /** 3 * 自定义linkedlist类 4 * @author acer 5 * 6 */ 7 public class mylinkedlist { 8 private Node first; 9 private Node last; 10 private int size; 11 public void add(Object obj

数据结构-List接口-LinkedList类-Set接口-HashSet类-Collection总结

一.数据结构:4种--<需补充> 1.堆栈结构:     特点:LIFO(后进先出);栈的入口/出口都在顶端位置;压栈就是存元素/弹栈就是取元素;     代表类:Stack;     其它:main方法最后一个出去; 2.数组结构:     特点:一片连续的空间;有索引,查找快;增删慢;     代表类:ArrayList;     应用场景:用于查询多的场景,如天气预报; 3.队列结构:     特点:FIFO(先进先出);入口/出口在两侧;     代表:Queue接口     应用场景

Android学习笔记-构建一个可复用的自定义BaseAdapter

转载自http://www.runoob.com/w3cnote/android-tutorial-customer-baseadapter.html   作者:coder-pig 本节引言: 如题,本节给大家带来的是构建一个可复用的自定义BaseAdapter,我们每每涉及到ListView GridView等其他的Adapter控件,都需要自己另外写一个BaseAdapter类,这样显得非常麻烦, 又比如,我们想在一个界面显示两个ListView的话,我们也是需要些两个BaseAdapter

java集合框架--ArrayList类、Vector和LinkedList类

1.ArrayList类概述 底层数据结构是数组,查询块,增删慢. 线程不安全,效率高. 2.ArrayList案例 2.1存储字符串并遍历 package com; import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; public class ArrayListDemo { public static void main(String[] args) { //创建ArrayL

java 16 -11 ArrayList存储自定义对象并增强for遍历

需求:ArrayList存储自定义对象并遍历.要求加入泛型,并用增强for遍历. A:迭代器 B:普通for     C:增强for LinkedList,Vector,Colleciton,List等存储继续练习 增强for是用来替迭代器. 1 package cn_JDK5new; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 6 7 public class ArrListDemo2 { 8 public st

自定义标签-自定义注解

首先是4个自定义注解类StaticResourceType.java public enum StaticResourceType { LESS,CSS,JS} StaticResource.java @Target({ElementType.FIELD})@Retention(RetentionPolicy.RUNTIME)public @interface StaticResource { StaticResourceType type(); String path(); Dependenc

java sqlite配置和自定义函数

资源 jetty Jetty Downloads地址 sqlite sqlite JDBC Driver 地址:bitbucket代码托管 和 Github代码托管 jetty配置sqlite 在jetty里的配置(工程MWeb为例) /MWeb/WebContent/WEB-INF/jetty-web.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE Configure PUBLIC &q