How do you write a method to print a LinkedList recursively, where by the method accepts a LinkedList and then passes the iterator to the recursive function for determining what is printed?
public void recurseALinkedList(LinkedList list) {
Iterator iter = list.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof LinkedList) {
recurseALinkedList((LinkedList) o);
} else {
// print the object
}
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.