shz.core.node.IDNode Maven / Gradle / Ivy
package shz.core.node;
/**
* 元素类型为int的双向链表节点
*
* 24*n(n为元素个数)
*
* B=16+24*n
*/
public class IDNode implements DNode {
private static final long serialVersionUID = 4737624808077729153L;
public int val;
protected IDNode next;
protected IDNode prev;
protected IDNode(int val) {
this.val = val;
}
public static IDNode of(int e) {
return new IDNode(e);
}
public static IDNode of() {
return of(0);
}
@Override
public final IDNode next() {
return next;
}
@Override
public final void next(IDNode node) {
next = node;
}
@Override
public final IDNode prev() {
return prev;
}
@Override
public final void prev(IDNode node) {
prev = node;
}
public final IDNode addNext(int e) {
return addNext(of(e));
}
public final IDNode addNext(int... es) {
IDNode next = this;
for (int e : es) next = next.addNext(e);
return next;
}
public final IDNode addPrev(int e) {
return addPrev(of(e));
}
public final IDNode addPrev(int... es) {
IDNode prev = this;
for (int e : es) prev = prev.addPrev(e);
return prev;
}
}