Hello, i took a test and had a problem with a function. I was wondering if someone could possibly explain the correct way of finding the answer. I have a final exam on this tomorrow and am still very confused! thanks for the help guys

Code:
for the function of p below, give the output of the call p(5)
void p( int x)
{
if (x<=0) return;
if (x%2==0) cout <<x<<endl;
p(x-1);
if (x%2 !=0) cout x<<endl;
}


for the function p below give the output of the call p(3)

void p (int x)
{
cout <<x<<endl;
if (x> 0) {p(x-1);p(x-1);}
}
for the first one i got only 5 but itshould be 4 2 1 3 5 and i have no idea how to figure that out

the second one should be 321001002100100

if any of you can explain how this concept works i would greatly appreciate it