Java - add a node to the end of a list?

前端 未结 8 653
有刺的猬
有刺的猬 2021-01-16 03:55

Here\'s what I have:

public class Node{
    Object data;
    Node next;

    Node(Object data, Node next){
        this.data = data;
        this.next = next         


        
8条回答
  •  野的像风
    2021-01-16 04:22

    Recursively navigate through each node until you hit the end.

    public void navigate(Node insertNode)
    {
        if(next == null)
            next = insertNode;
        else
            next.navigate(insertNode);
    }
    

提交回复
热议问题