LinkedList Java traverse and print

后端 未结 4 1798
轮回少年
轮回少年 2020-12-20 07:41

I would really appreciate if you can help to answer to this question:

I have already created a custom linked list myself in a very standard way using Java. Below are

4条回答
  •  感动是毒
    2020-12-20 08:19

    Your linkedList class already creates the Nodes for you!

    linkedList list = new linkedList();
    list.add("foo");
    list.add("bar");
    Node tmp = lst.getHead();
    while(tmp != null){
        System.out.println(tmp.getData());
        tmp = tmp.getNext();
    }
    

    Will print

    foo
    bar
    

提交回复
热议问题