我正在尝试了解垃圾收集。在学习的过程中,我找到了这段代码,并且被困在这里。
class Stack{
private Node top;
public void push(Customer customer){
Node node=new Node(customer);
node.next=top;
top=node;
}
public void clear(){
top=null;
}
public Customer pop(){
if(top!=null){
Customer customer=top.customer;
top=top.next;
return customer;
}else{
return null;
}
}
public String toString(){
String list="[";
Node temp=top;
while(temp!=null){
list+=temp.customer+", ";
temp=temp.next;
}
list+=top!=null ? "\b\b]": "empty]";
return list;
}
class Node{
private Customer customer;
private Node next;
Node(Customer customer){this.customer=customer;}
}