这段代码中“节点”的功能是什么?

时间:2019-05-30 12:40:55

标签: java nodes

我正在尝试了解垃圾收集。在学习的过程中,我找到了这段代码,并且被困在这里。

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;}
    }

0 个答案:

没有答案