shz.core.node.ISNode Maven / Gradle / Ivy
package shz.core.node;
/**
* 元素类型为int的单向链表节点
*
* 16*n(n为元素个数)
*
* B=16*(n+1)
*/
public class ISNode implements SNode {
private static final long serialVersionUID = 6070178940920776580L;
public int val;
protected ISNode next;
protected ISNode(int val) {
this.val = val;
}
public static ISNode of(int e) {
return new ISNode(e);
}
public static ISNode of() {
return of(0);
}
@Override
public final ISNode next() {
return next;
}
@Override
public final void next(ISNode node) {
next = node;
}
@Override
public final ISNode addPrev(ISNode node) {
addNext(node);
int val = this.val;
this.val = node.val;
node.val = val;
return this;
}
@Override
public final void poll() {
if (next != null) {
this.val = next.val;
next = next.next;
} else this.val = 0;
}
public final ISNode addNext(int e) {
return addNext(of(e));
}
public final ISNode addNext(int... es) {
ISNode next = this;
for (int e : es) next = next.addNext(e);
return next;
}
public final ISNode addPrev(int e) {
return addPrev(of(e));
}
public final ISNode addPrev(int... es) {
for (int e : es) addPrev(e);
return this;
}
}