//C# program that uses recursive
method
using System;
using
System.Collections.Generic;
using
System.Linq;
class Program
{
static void Main()
{
// ... Call recursive method directly.
List<int> list = new List<int>();
X(list, 0);
// ... Verify
sum.
Console.WriteLine(list.Sum());
}
static void X(List<int> list, int value)
{
if (list.Count < 10)
{
list.Add(value);
X(list, value + 1);
}
}
}
//C# program that inlines recursive
call
using System;
using
System.Collections.Generic;
using
System.Linq;
class Program
{
static void Main()
{
// ... Inline first recursive call.
List<int> list = new List<int>();
if (list.Count < 10)
{
list.Add(0);
X(list, 0 + 1);
}
// ... Verify
sum.
Console.WriteLine(list.Sum());
}
static void X(List<int> list, int value)
{
if (list.Count < 10)
{
list.Add(value);
X(list, value + 1);
}
}
}
using System;
{
static void Main()
// ... Call recursive method directly.
List<int> list = new List<int>();
Console.WriteLine(list.Sum());
}
if (list.Count < 10)
list.Add(value);
X(list, value + 1);
}
}
}
using System;
{
static void Main()
// ... Inline first recursive call.
List<int> list = new List<int>();
list.Add(0);
X(list, 0 + 1);
}
Console.WriteLine(list.Sum());
}
if (list.Count < 10)
list.Add(value);
X(list, value + 1);
}
}
}
No comments:
Post a Comment