Question in data structure

Using the static structures write a program to represent calling of recursive functions in the next program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
f1(int);

int main()
{
  f1(6);
  retrun 0;
}
f1(int y)
{
  if(y == 0)
    return 0;
  else
    f1(y-1);
    cout << y;
}


I did not understand the question a good understanding

so I answered him this way

Is it correct or not?

And if not

Please explain me the question!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stack>
#include <iostream>

using namespace std;

stack<int> myStack;

int add2stack(int array[], int size);

int main()
{
    int array[] = {6, 5, 4, 3, 2, 1};

    add2stack(array, 5);

    while(!myStack.empty())
    {
        cout << myStack.top() << " ";
        myStack.pop();
    }
    return 0;
}

int add2stack(int array[], int size)
{
    if(size < 0)
        return 0;

    else
    {
        myStack.push(array[size]);
        return add2stack(array, size - 1);
    }
}
Topic archived. No new replies allowed.