All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.linked.LSNode Maven / Gradle / Ivy

package shz.linked;

/**
 * 元素类型为E的单向链表节点
 * 

* [16+E(类型字节)+对齐填充]*n(n为元素个数) *

* B=16*(n+1)+(E+对齐填充)*n */ @SuppressWarnings("unchecked") public class LSNode implements SNode { public E val; protected LSNode next; protected LSNode(E val) { this.val = val; } public static LSNode of(E e) { return new LSNode<>(e); } public static LSNode of() { return of(null); } @Override public final LSNode next() { return next; } @Override public final void next(SNode node) { next = (LSNode) node; } @Override public final LSNode addPrev(SNode node) { addNext(node); E val = this.val; LSNode lsNode = (LSNode) node; this.val = lsNode.val; lsNode.val = val; return this; } @Override public final void poll() { if (next != null) { this.val = next.val; next = next.next; } else this.val = null; } public final LSNode addNext(E e) { return (LSNode) addNext(of(e)); } @SafeVarargs public final LSNode addNext(E... es) { LSNode next = this; for (E e : es) next = next.addNext(e); return next; } public final LSNode addPrev(E e) { return addPrev(of(e)); } @SafeVarargs public final LSNode addPrev(E... es) { for (E e : es) addPrev(e); return this; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy