java中有这个类吗?

来源:百度知道 编辑:UC知道 时间:2024/06/05 14:15:50
StackOfIntegers

如果有 在哪个包里?

public class StackOfIntegers {
private int[] elements;
private int size;
public static final int MAX_SIZE = 16;

/** Construct a stack with the default capacity 16 */
public StackOfIntegers() {
this(MAX_SIZE);
}

/** Construct a stack with the specified maximum capacity */
public StackOfIntegers(int capacity) {
elements = new int[capacity];
}

/** Push a new integer into the top of the stack */
public int push(int value) {
if (size >= elements.length) {
int[] temp = new int[elements.length * 2];
System.arraycopy(elements, 0, temp, 0, elements.length);
elements = temp;
}

return elements[size++] = value;
}

/** Return and remove the top element from the stack */
public int pop() {
return elements[--size];
}

/** Return the top element from the stack */