A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张玉建 中级黑马   /  2013-8-20 19:51  /  1969 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class  dome22
{
static String str= "123456";
static char[] ch=str.toCharArray();
static int n= 6;
static void swap (int a1,int a2)
{
  char temp = ch[a1];
  ch[a1]=ch[a2];
  ch[a2]=temp;
}
static void sort(int index)
{
  int i;
  if (index==n)
  {
   for ( i=0;i<n ;i++ )
   {
    System.out.println(ch[i]);
   }
   System.out.println("");
   return;
  }
  for (i=index;i<n ;i++ )
  {
   swap(index,i);
   sort(index + 1);
   swap(index,i);
  }
}

public static void main(String[] args)
{
  for (int s=0;s<n ;s++ )
  {
   sort(s);
  }
}
}
求排列求解,
不知道那出错了!还出现了相同的排列,
求解释!

评分

参与人数 1技术分 +1 收起 理由
田磊阳 + 1

查看全部评分

4 个回复

倒序浏览
你是想按照不同的顺序排列吗?
回复 使用道具 举报
我写的个关于全排列的博客,给你看看http://blog.csdn.net/woshi765284862/article/details/10128029

评分

参与人数 1技术分 +1 收起 理由
田磊阳 + 1

查看全部评分

回复 使用道具 举报
http://blog.csdn.net/woshi765284862/article/details/10128029
回复 使用道具 举报
blog写的好!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马