一、双向链表
数据结构:
class Node{
Node pre;
Node next;
Object value;
Node(){
}
Node(Node pre,Object value,Node next){
this.value =value;
this.pre= pre;
this.next =next;
}
}
Node first;
Node last;
int capacity = 0; //实际大小
具体增加、删除、查询操作
public class listTest {
class Node{
Node pre;
Node next;
Object value;
Node(){
}
Node(Node pre,Object value,Node next){
this.value =value;
this.pre= pre;
this.next =next;
}
}
Node first;
Node last;
int capacity = 0; //实际大小
listTest(){
}
/**
* 添加节点
* @param value
*/
public Node addNode(Object value){
Node e = new Node(null,value,null);
if(first == null){
//第一个节点第一次插入
first = last = e;
}else{
last.next = e;
e.pre = last;
last = e;
}
capacity ++;
return e;
}
/**
* 某个位置添加节点
* @param index
* @param value
*/
public Boolean addNodeIndex(int index,Object value){
if(index <0 || index > capacity) return false;
Node e = new Node(null,value,null);
if(index == 0){
//插入头部
if(first == null) last = e;
else e.next = first;
first = e;
}else if(index == capacity - 1){
//插入尾部
e.pre = last;
last = e;
}else{
//插入中间
Node indexNo = getNode(index);
indexNo