2
进出口工作在LinkedListStack
并具有打印出如“大小”。 这里是我的LinkedListStack
:LinkedListStack的System.out.println
public class LinkedListStack {
private class Element {
public Object value;
public Element next;
}
private Element top;
private int size=0;
public void push(Object o) {
Element e=new Element();
e.value=o;
e.next=top;
top=e;
size++;
}
public Object pop() {
if (top!=null) {
Object v=top.value;
top=top.next;
size--;
return v;
} else {
return null;
}
}
public boolean isEmpty(){
return top==null;
}
public int size() {
return size;
}
public Object get(int n) {
Element current=top;
int i=0;
while (i<n && current!=null) {
current=current.next;
i++;
}
if (current==null)
return null;
else
return current.value;
}
}
我知道我必须使用
System.out.println ("...");
,而我需要一个新的类,我们称之为Stacki
。必须包含main
方法,我可以使用这些方法并将它们打印出来。因此,这将是:
public class Stacki {
public static void main(String[] args) {
}
}
我怎么把
public void size() {
System.out.println ("size is"+size());
}
在这门课吗?因为我不能像这样使用块,所以会发生错误。
谢谢:)
您需要首先定义** LinkedListStack **的“对象” – Null