堆栈实现。我们如何在 Node 类中创建“Node”类型字段?“节点”类型的变量“第一个”如何包含“节点”类型的字段?谢谢你的帮助
public class Stack
{
private Node first = null;
private class Node
{
String item;
Node next;
}
public boolean isEmpty()
{
return first == null;
}
public void push(String item)
{
Node oldFirst = first;
first = new Node();
first.item = item;
first.next = oldFirst;
}
public String pop()
{
String item = first.item;
first = first.next;
return item;
}
}