Skip to content

如何遍历链表

使用迭代器或者递归

简单的代码:

Iterator<String> iter = linkedKist.iterator();
while(iter.hasNext()) {
String element = iter.next();
System.out.println(element);
}
public void traverseLinkedList(Node node) {
if (node != null) {
// do something
traverseLinkedList(node.next);
}
}