welcome to Qijie's Blog 薛其杰
代码
        static void PrintSequenceString(string inputStr)
        {
            
if (string.IsNullOrEmpty(inputStr))
                
throw new ArgumentNullException(string.Format("{0} is illegal", inputStr));
            
            
char[] chr = inputStr.ToCharArray();
            List
<string> results = new List<string>();
            Generate(chr, 
0, results);
            
            
foreach (string s in results)
            {
                Console.WriteLine(s);
            }
        }

        
static void Generate(char[] chr, int index, List<string> results)
        {
            
if (index == chr.Length)
                results.Add(
new string(chr));
            
for (int i = index; i < chr.Length; i++)
            {
                swap(chr, i, index);
                Generate(chr, index
+1, results);
                swap(chr, index, i);
            }
        }

        
static void swap(char[] chr, int i, int j)
        {
            
char tmp = chr[i];
            chr[i] 
= chr[j];
            chr[j] 
= tmp;
        }

 

posted on 2010-02-09 12:46  零点零一  阅读(362)  评论(0编辑  收藏  举报