【发布时间】:2015-09-07 11:02:52
【问题描述】:
这是对堆栈中的项目进行计数的好方法吗?我不确定这是否是正确的实现方法
private someList<E> stack;
public int countItems(){
Stack<E> newStack = new Stack<E>();
int count = 0;
while(!stack.isEmpty()){
newStack.push(this.pop());
count++;
}
for(int i = 0; i < count; i++) {
this.push(newStack.pop());
}
return count;
}
【问题讨论】:
标签: java list generics stack adt