我对“不实现 ADT(抽象数据类型)的要求感到困惑。实现 push()、pop() 和 isEmpty()。我可以从接口单独实现这些方法,还是在 linkedStack 类中本地创建这些方法?
`
public class linkedStack<T>
{
private int count;
private LinearNode<T> top;
private T [] stack;
public void push (T data) {stack[top++] = data;}
public T pop() {T result = stack[--top]; stack[top] = null;return result;}
public boolean isEmpty() {return (top == 0);}
public linkedStack()
{count = 0;top = null;}
public String toString ()
{
String result = "\n";
String[][] grid = null;
for (int row=0; row < grid.length; row++)
{ for (int column=0; column < grid[row].length; column++)
result += grid[row][column] + "";
result += "\n";
}
return result;
}
public class LinearNode<T>
{
private LinearNode<T> next;
private T element;
public LinearNode () {next = null;element = null;}
public LinearNode (T elem){next = null;element = elem;}
}
}
`