我很满意“不要实现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;}
}
}
`
答案 0 :(得分:0)
ADT就像构建数据结构的蓝图所以我假设他们不希望你实现所有方法(即实现ADT),而只是方法pop()
,push()
和isEmpty()