输出一个集合的所有项目。

类别:.NET开发 点击:0 评论:0 推荐:

有集合
string[] NumC={"0","1","2","3","4","5","6","7","8","9"};
要输出如下形式:
0
1
...
9
01
02
...
89
012
...
789
...
0123456789

写了一个递归算法实现如下功能。

string[] NumC={"0","1","2","3","4","5","6","7","8","9"};
  

  private void button1_Click(object sender, System.EventArgs e)
  {
   for(int i=1;i<=NumC.Length;i++)
   {
    BuildNum(i,0,"");
   }
  }

  private void BuildNum(int level,int start,string num)
  {
   for(int i=start;i<NumC.Length;i++)
   {
    if(level==1)
    {
     listBox1.Items.Add(num+NumC[i]);
    }
    else
    {
     BuildNum(level-1,i+1,num+NumC[i]);
    }
   }
  }


程序用C#写的,算法效率上不是最好的,只是实现这个功能而已,
初次写文,兄弟们谅解!!!

本文地址:http://com.8s8s.com/it/it42483.htm