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

shz.core.stack.a.ZArrayStack Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
package shz.core.stack.a;

import shz.core.ArrayHelp;
import shz.core.function.BooleanConsumer;

import java.util.Arrays;
import java.util.Objects;

/**
 * 元素类型为boolean基于动态数组的栈
 * 

* 24+n(n为元素个数)=es *

* B=48+n+对齐填充 */ public class ZArrayStack extends ArrayStack { private static final long serialVersionUID = 278312812174285655L; protected boolean[] es; public ZArrayStack(int capacity) { super(capacity); es = new boolean[capacity]; } public ZArrayStack() { this(DEFAULT_CAPACITY); } public static ZArrayStack of(int capacity) { return new ZArrayStack(capacity); } public static ZArrayStack of() { return new ZArrayStack(); } @Override protected final void resize(int capacity) { this.capacity = capacity; es = Arrays.copyOf(es, capacity); } @Override protected final void setNull(int i) { es[i] = false; } public final void push(boolean e) { beforePush(); es[size++] = e; } public final boolean pop() { checkEmpty(); boolean e = es[--size]; afterPop(); return e; } public final boolean peek() { checkEmpty(); return es[size - 1]; } public final void reverse() { if (size > 1) ArrayHelp.reverse(es, 0, size); } public final void forEach(BooleanConsumer action) { Objects.requireNonNull(action); int current = size; while (current > 0) action.accept(es[--current]); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy