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

shz.stack.DArrayStack Maven / Gradle / Ivy

package shz.stack;

import java.util.Arrays;

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

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

* B=48+8*n */ public class DArrayStack extends ArrayStack { protected double[] es; protected DArrayStack(int capacity) { super(capacity); es = new double[capacity]; } public static DArrayStack of(int capacity) { return new DArrayStack(capacity); } public static DArrayStack of() { return of(DEFAULT_CAPACITY); } @Override protected final Double get(int i) { return es[i]; } @Override protected final void resize(int capacity) { this.capacity = capacity; es = Arrays.copyOf(es, capacity); } @Override protected final void setNull(int i) { es[i] = 0d; } public final void push(double e) { beforePush(); es[size++] = e; } public final double pop() { double e = es[--size]; afterPop(); return e; } public final double peek() { return es[size - 1]; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy