代码拉取完成,页面将自动刷新
package second_term.second_week;
import second_term.first_week.EmptyCollectionException;
import second_term.first_week.StackADT;
public class LindedStack<T> implements StackADT<T> {
private int count;//用于计算栈中元素的个数
private LinearNode<T> top;//指向顶栈的指针
public LindedStack(){
count = 0 ;
top = null;
}
@Override
public T pop() {
if (isEmpty())
throw new EmptyCollectionException("Stack");
T result = top.getElement();
top = top.getNext();
count--;
return result;
}
@Override
public void push(T element) {
LinearNode<T> temp = new LinearNode<T>(element);
temp.setNext(top);
top = temp;
count++;
}
@Override
public T peek() throws EmptyCollectionException
{
if (isEmpty()){
throw new EmptyCollectionException("Stack");}
T result = top.getElement();
return result;
}
@Override
public boolean isEmpty() {
if (count == 0)
return true;
else
return false;
}
@Override
public int Size() {
return count;
}
public String toString(){
String result="";
for (int i =0;i<count;i++){
System.out.println(top.getElement());
top = top.getNext();
}
return result;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。