思路:head为头节点,数组e[]储存每个节点的值,ne[]储存每个节点指向的下一节点的索引(位置),idx为当前数组储存到了哪个位置。
其次实现了插入、删除的功能。
package com.dzy;
public class linkNode{
final int N=100010;
int head;
int[] e=new int[N];//储存每个节点的元素值
int[] ne=new int[N];//储存每个节点的下一节点的索引
int idx;//储存当前数组e的储存位置(到哪一个节点)
public void init(){
head=-1;
idx=0;
}
public void add_to_head(int x){
e[idx]=x;
ne[idx]=head;
head=idx;
idx++;
}
public void add(int k,int x){
e[idx]=x;
ne[idx]=ne[k];
ne[k]=idx;
idx++;
}
public void remove(int k){
ne[k]=ne[ne[k]];
}
public void remove_head(){
head=ne[head];
}
}



