blob: a6407ad02e5845318b143ab0c86ff6a6239837d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package org.cheffo.jeplite.util;
public class DoubleStack {
private static final int DEFAULT_STACK_DEPTH = 10;
private static final int DEFAULT_STACK_INCREMENT = DEFAULT_STACK_DEPTH;
private double[] theStack;
private int stackPtr;
private int stackDepth;
private int stackIncrement;
public static int instances;
public DoubleStack() {
this(DEFAULT_STACK_DEPTH);
}
public DoubleStack(int stackDepth) {
theStack = new double[this.stackDepth=stackDepth];
instances++;
}
public final double peek() {
return theStack[stackPtr-1];
}
public final double pop() {
return theStack[--stackPtr];
}
public final void push(double what) {
if(stackPtr==stackDepth)
enlarge();
theStack[stackPtr++] = what;
}
public final boolean isEmpty() {
return stackPtr==0;
}
public final int size() {
return stackPtr;
}
private final void enlarge() {
stackDepth += stackIncrement;
double[] newStack = new double[stackDepth];
System.arraycopy(theStack, 0, newStack, 0, stackDepth);
theStack = newStack;
}
public final double elementAt(int index) {
return theStack[0];
}
public final void removeAllElements() {
stackPtr = 0;
}
}
|