for learning the recursion, i extend the recursion method from following link: how recursion works followoing is my code:
class Program
{
static void Main(string[] args)
{
Method(3,1,2);
Console.ReadLine();
}
public static void Method(int flowerInVase, int a, int b)
{
if (flowerInVase > 0)
{
Method(flowerInVase - 1,b,a);
Console.WriteLine(+flowerInVase+", "+a+" ,"+b);
}
}
following is the output:
1, 1 ,2
2, 2 ,1
3, 1 ,2
I understood stack concept, but not understanding switching of values a and b in 3rd iteration. after calling method(3) recursively, when flowerInVase=1, shouldn't the values of a=2 and b=1 respectively, as the recursive function method(flowerInVase - 1,b,a) gets called. Need to understand how recursive function works in this case