
9个回答
展开全部
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 */
public int peek() {
return elements[size - 1];
}
/** Test whether the stack is empty */
public boolean empty() {
return size == 0;
}
/** Return the number of elements in the stack */
public int getSize() {
return size;
}
}
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 */
public int peek() {
return elements[size - 1];
}
/** Test whether the stack is empty */
public boolean empty() {
return size == 0;
}
/** Return the number of elements in the stack */
public int getSize() {
return size;
}
}
展开全部
明确告诉你,标准版JAVA类库中没有这个类!完毕
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看在什么包里,不就能确定了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
API一查不就知道了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己下个中文API不就可以查询了,这也问哦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己查下API就知道了,告诉你,没有!我用的是5.0的,自己定义个!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询