用C#写的全排列

2008-07-22 15:13:53.0     推荐:0    收藏:0    评论:0     来源:中国IT实验室
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace perm
{
class Program
{
static void permlist(int[] listdata, int k, int m)
{
if (k == m)
{
for (int i = 0; i <= m; i++) System.Console.Write(listdata[i]);
Console.WriteLine();
}
else
for (int i = k; i <= m; i++)
{
Swap(ref listdata[k],ref listdata[i]);
permlist(listdata, k + 1, m);
Swap(ref listdata[k],ref listdata[i]);
}
}
static void Swap(ref int a,ref int b)
{
int temp = a; a = b; b = temp;
}
static void Main(string[] args)
{
int[] listdata = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
permlist(listdata, 0, 3);
}
}
}
您可以针对本文进行:[评论]  [收藏]  [推荐]  
  • 共有0条评论  点击查看更多评论
  • 网友评论仅供网友表达个人看法,并不表明e800同意其观点或证实其描述
我想发表评论:
用户名密码
  • 匿名发表
    验证码: