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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!