C# code as below:
class Program
{
static void Main(string[] args)
{
Method("123");
Console.ReadKey();
}
static void Method(string str,string str2="")
{
if (str == null)
return;
if (str == string.Empty)
Console.WriteLine(str2);
for (int i = 0; i < str.Length; i++)
{
Method(str.Remove(i, 1), str2+str[i].ToString());
}
}
}
output:

本文通过一个具体的C#代码示例展示了如何使用递归算法处理字符串,并演示了如何在递归过程中传递不同的参数组合。
1237

被折叠的 条评论
为什么被折叠?



