你可以看看
http://community.csdn.net/Expert/topic/3502/3502682.xml?temp=.62698

解决方案 »

  1.   

    我给你写了一个看看吧:)using System;namespace ConsoleApp
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class Class1
    {
    struct word
    {
    public char chWord;
        
    public int index;
    };
    static word[] g_wordOut; /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    word[] Test; int nLen=0;
    System.Console.WriteLine("请输入要进行排列的元素的个数"); nLen = int.Parse(System.Console.ReadLine());
    System.Console.WriteLine("请输入 {0} 个元素", nLen);
    // 动态分配内存
    Test=new word[nLen];
    for(int i=0;i<nLen;i++)
    {
    Test[i].chWord = (char)System.Console.Read();
           
    Test[i].index=-1;
    }
    g_wordOut=new word[nLen];
    for( int i=0;i<nLen;i++)
    {
           
    Test[i].index=-1;
    }
       
    System.Console.WriteLine("排列组合如下:");
        
    format(Test,0,nLen);
    }
    static void format(word[] test,int dex,int Len)
    {
    word[] pWord=test;
    for(int i=0;i<Len;i++)
    {
    if(pWord[i].index!=-1)
    continue;
    g_wordOut[dex].chWord=pWord[i].chWord;
    pWord[i].index=1;
    if(dex==Len-1)
    {
    for(int x=0;x<Len-1;x++)
    {
    System.Console.Write(g_wordOut[x].chWord);
    }
    System.Console.WriteLine(g_wordOut[Len-1].chWord);
    }
    format(pWord,dex+1,Len);
    pWord[i].index=-1;
    }
    }
    }
    }