0

我对“不实现 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;}


  }  
}


`
4

1 回答 1

0

ADT 就像构建数据结构的蓝图,所以我假设他们不希望您实现所有方法(即实现 ADT),而只实现方法pop()push()并且isEmpty()

于 2012-09-28T00:39:11.160 回答