我写了这段代码,但在isEmpty方法上出错,说找不到符号?
import java.io.*;
import java.util.Scanner;
public class ITDLinkedStack{
public int peek()
{
if (isEmpty()) // this is where i get the error
throw new RuntimeException("Peek attempted on empty stack");
else
return top.data;
}
}
在您发布的这段代码中,您排除了代码的其余部分。如果你把它添加到你的代码中,你的行就可以工作了!
if (isEmpty()) // this is where i get the error
throw new RuntimeException("Peek attempted on empty stack");
else
return top.data;