Micheal Cowan Micheal Cowan - 2 years ago 93
Java Question

Returning a Linked List with recursion when the function takes a single int argument?

I'm struggling with a function involving Lucas numbers. I need to write a
recursive function that takes a single integer argument n and returns a linked list that contains the first n Lucas numbers. I just need to understand how to recursively return a linked list with only an int argument.

Answer Source

Use a helper function. In pseudo-code:

List <- lucas(int n) {
     lucasHelper(new LinkedList(), n);

List <- lucasHelper(List list, int n) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download