您的位置:首页 > 编程语言 > Go语言

自己实现全排列:I found some old code were good:We should think in a reverse way

2009-06-23 16:30 507 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace zuhe
{
class Program
{
static public void zuhe(char[] c, StringBuilder s, int level)
{
for (int i = level; i < c.Length; i++)
{
s.Append(c[i]);
Console.WriteLine(s);
if (level < c.Length - 1)
{
level++;
zuhe(c, s,level);
}
s.Length -= 1; //setting lower length to differ the new stringbuider from the old
}
}

static void Main(string[] args)
{
string me = "abcd";
char[] my = me.ToCharArray();
StringBuilder sb = new StringBuilder();
zuhe(my, sb, 0);
Console.ReadKey();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐