2012-09-28 131 views
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;} 


    } 
} 


` 
+2

他们提供了一个界面吗?也是一个Java大会开始你的类名大写'公共类LinkedStack ' – gtgaxiola

回答

0

的ADT就像一个蓝图构建一个数据结构,所以我假设他们不想让你实现所有的方法(即实现ADT),但只有方法pop(),push()isEmpty()