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;}
}
}
`
他們提供了一個界面嗎?也是一個Java大會開始你的類名大寫'公共類LinkedStack' –
gtgaxiola