2024-06-14 05:57:38 +00:00
|
|
|
public class TestRecursion {
|
|
|
|
|
|
|
|
public int value = 0;
|
|
|
|
public TestRecursion child = null;
|
|
|
|
|
|
|
|
public TestRecursion(int n)
|
|
|
|
{
|
2024-06-17 17:25:24 +00:00
|
|
|
this.value = n;
|
2024-06-14 05:57:38 +00:00
|
|
|
|
|
|
|
if(n > 0)
|
|
|
|
{
|
|
|
|
child = new TestRecursion(n - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int fibonacci(int n)
|
|
|
|
{
|
|
|
|
if(n < 2)
|
|
|
|
{
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return fibonacci(n - 1) + this.fibonacci(n - 2);
|
|
|
|
}
|
2024-06-21 06:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int ackermann(int m, int n)
|
|
|
|
{
|
|
|
|
if (m == 0) return n + 1;
|
|
|
|
if (n == 0) return ackermann(m - 1, 1);
|
|
|
|
return ackermann(m - 1, ackermann(m, n - 1));
|
|
|
|
}
|
2024-06-14 05:57:38 +00:00
|
|
|
}
|