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

shz.core.stack.a.FArrayStack 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.FloatConsumer;

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

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

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

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy