Mutual Recursion: A programming technique where two or more functions call each other. It's essential to ensure that mutual recursion progresses towards a base case to avoid infinite recursion and non-terminating programs.
isEven Function:
int isEven(unsigned int n) {
if (n == 0) {
return 1; // Base case
}
if (n == 1) {
return 0; // Base case
}
return isOdd(n - 1); // Call isOdd for complex step
}
isOdd Function:
int isOdd(unsigned int n) {
if (n == 0) {
return 0; // Base case
}
if (n == 1) {
return 1; // Base case
}
return isEven(n - 1); // Call isEven for complex step
}
Complete Example with Prototypes:
int isOdd(unsigned int n); // Prototype for isOdd
int isEven(unsigned int n) {
if (n == 0) {
return 1;
}
if (n == 1) {
return 0;
}
return isOdd(n - 1);
}
int isOdd(unsigned int n) {
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
return isEven(n - 1);
}
parseExpression
for each argument.parseCall
if it encounters a function call.Example:
f(3, g(42), h(x, y, z(1)))
f
and its arguments.parseCall
when encountering function calls like g(42)
and h(x, y, z(1))
.