im stuck

Hey guys im experimenting on void recursive function,
and i dont understand why the ouput of this program is
{1 2 1 3 1 2 1 }
because the next number to 3 is 2 and then 1
so the output should be {1 2 3 2 1}
please help! i dont understand ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main(void)
{
	int x=3;
	hanoi(x);
}
void hanoi(int x)
{
	if(x==1) {
		cout<<x<<" ";
	}
	else 
	{	
		hanoi(x-1);
		cout<<x<<" ";
		hanoi(x-1);
		//out<<x<<" ";.
		
	}	
}
Step through it using a debugger. it's fairly easy to see what's going on then.
but it's essentially when x is 3 you are calling hanoi(x-1) twice in succession.
sorry
Topic archived. No new replies allowed.