GalaxyPilot —— D.S


                  生命不熄,戰斗不止
          數據加載中……

          求0-9的全排列,參考了網上的代碼

          public class qpl
          {
          ?public static void main(String[] args)
          ?{
          ??char num[]={'0','1','2','3','4','5','6','7','8','9'};
          ??permutation(num,0,10);
          ?}
          ?public static void permutation(char num[] , int start , int len)
          ?{
          ??int i;
          ??char t;
          ??if (start < len - 1)
          ??{
          ???permutation(num, start+1,len);
          ???for (i=start+1;i<len;i++)
          ???{
          ????t=num[start];
          ????num[start]=num[i];
          ????num[i]=t;
          ????permutation(num,start+1,len);
          ????t=num[start];
          ????num[start]=num[i];
          ????num[i]=t;
          ???}
          ??}else
          ???System.out.println(num);
          ?}
          }

          posted on 2006-09-07 09:13 舵手 閱讀(2570) 評論(2)  編輯  收藏

          評論

          # re: 求0-9的全排列,參考了網上的代碼  回復  更多評論   

          看這代碼,想起了重構,同樣的代碼出現了兩次
          t=num[start];
          num[start]=num[i];
          num[i]=t;
          沒有考慮算法,只是對代碼而論。重復是一切罪惡之源。
          2006-09-09 10:09 | 布衣郎

          # re: 求0-9的全排列,參考了網上的代碼  回復  更多評論   

          有些重復是必要的,人類一代一代的繁衍,不也是一種重復?
          2006-09-15 17:17 | che

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 永济市| 卓资县| 承德县| 丰宁| 凯里市| 南昌市| 保亭| 香港 | 宜章县| 古田县| 普定县| 五台县| 瓦房店市| 淄博市| 重庆市| 梅河口市| 康保县| 昔阳县| 通化市| 财经| 吉隆县| 阿坝| 梁平县| 齐齐哈尔市| 平定县| 阿瓦提县| 会泽县| 博罗县| 文安县| 崇阳县| 新晃| 永福县| 沿河| 静海县| 丹阳市| 阿拉尔市| 镶黄旗| 克山县| 吴江市| 句容市| 萍乡市|