- #1

- 11

- 0

can someone explain java recursion to me?

Last edited:

- Java
- Thread starter physicsfun
- Start date

- #1

- 11

- 0

can someone explain java recursion to me?

Last edited:

- #2

- 492

- 0

Basically, you have functional recursion and type recursion. Type recursion would be like a linked list. Functional recursion would be like a function calling itself. For instance...

Code:

```
class LinkedNode
{
public int data;
public LinkedNode next;
}
```

LinkedNode : null | int & LinkedNode.

For functions...

Code:

```
int factorial(int n)
{
if(n<=0)
return 1;
else
return n * factorial(n-1);
}
```

Basically, recursive definitions need a base case (null, n<=0) and a recursive part (some new information PLUS some (usually smaller) instance of the very same definition).

- #3

- 261

- 2

- Replies
- 5

- Views
- 607

- Last Post

- Replies
- 12

- Views
- 733

- Replies
- 10

- Views
- 2K

- Last Post

- Replies
- 8

- Views
- 924

- Replies
- 7

- Views
- 1K

- Last Post

- Replies
- 12

- Views
- 80K

- Last Post

- Replies
- 5

- Views
- 906

- Last Post

- Replies
- 2

- Views
- 10K

- Last Post

- Replies
- 13

- Views
- 996

- Replies
- 7

- Views
- 5K