Question
Question 6: Rewrite without recursion Here is a recursive function which computes something quite simple given a list of integers. void mystery_fxn(int l[], int n)
Question 6: Rewrite without recursion
Here is a recursive function which computes something quite simple given a list of integers.
void mystery_fxn(int l[], int n)
{
if (n < 2) return;
mystery_fxn(l, n-1);
int t = l[n-2];
l[n-2] = l[n-1];
l[n-1] = t;
}
The function mystery_fxn is used by calling it with the first argument being the array, the second being the number of elements in the array, like such:
int l[] = {100,200,300,400};
mystery_fxn(l, 4);
Examine the code and determine what mystery_fxn does. Then write an equivalent function without recursion. Your function should be a replacement, that is, it should handle all the same inputs as mystery_fxn and give an identical result.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started