<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Feng.Li's Java See

    抓緊時間,大步向前。
    隨筆 - 95, 文章 - 4, 評論 - 58, 引用 - 0
    數據加載中……

    全排列的遞歸算法

    void perm(char *list, int i, int n){
    int j,temp;
    if(i == n){
    for(j = 0; j < n; j++)
    cout<<list[j];
    cout<<" ";
    }
    else{
    for(j = i; j < n; j++){
    SWAP(list[i],list[j],temp);
    perm(list,i+1,n);
    SWAP(list[i],list[j],temp);
    }

    for(j = i; j < n; j++){
    SWAP(list[i],list[j],temp); //將第j數字做為第一個
    perm(list,i+1,n);
    SWAP(list[i],list[j],temp); //將第j數字換回原來位置,準備用第j+1個做做為第一個

    }
    -----------------------------------------------------------
    建議你將函數修改成以下形式,自己觀察一下
    -----------------------------------------------------------
    void perm(char *list, int i, int n){
    int j,temp;
    for(j = 0; j < n; j++)
    cout<<list[j]<<endl;
    if(i == n){
    for(j = 0; j < n; j++)
    cout<<list[j];
    cout<<" "<<i=n了<<" ";
    }
    else{
    for(j = i; j < n; j++){
    SWAP(list[i],list[j],temp);
    perm(list,i+1,n);
    SWAP(list[i],list[j],temp);

    }
    ========================================================================================================

    下面是完整的程序:C#

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                char[] list = {'a','b','c','d' };
                perm(list, 0, 4);
                Console.ReadLine();
            }
            static void perm(char[] list, int i, int n)
            {
                int j,temp;
                if(i==n)
                {
                 
                    for(j=0;j<n;j++)
                    {
                        Console.Write(list[j]);
                        //Console.WriteLine();
                    }
                }
                else

                   
                {
                   
                    for (j=i;j<n;j++)
                    {
                        swap(ref list[i],ref list[j]);
                        perm(list,i+1,n);
                        swap(ref list[i], ref list[j]);
                    }
                }
            }
            static void swap(ref char  a, ref char  b)
            {
                char c = a;
                a = b;
                b = c;
               
              
            }
        }
    }


    posted on 2007-10-09 08:58 小鋒 閱讀(467) 評論(0)  編輯  收藏 所屬分類: algorithm

    主站蜘蛛池模板: 一级全免费视频播放| 三上悠亚电影全集免费| 亚洲中文字幕在线乱码| 8090在线观看免费观看| 18禁亚洲深夜福利人口| 亚洲an天堂an在线观看| 亚洲国产成人久久笫一页| 久久免费动漫品精老司机| 国产成人人综合亚洲欧美丁香花| 亚洲国产中文在线二区三区免| 在线观看的免费网站| 亚洲精品无码AV人在线播放 | 久久亚洲中文字幕精品一区四| 久久国产免费一区二区三区| 亚洲人成网站999久久久综合| 久久久亚洲精品蜜桃臀| 青青青国产在线观看免费网站 | 国产精品青草视频免费播放| 亚洲图片中文字幕| 亚洲一区二区三区AV无码 | 亚洲精品无码不卡| 亚洲国产日韩成人综合天堂| 黄页网站免费在线观看| 精品人妻系列无码人妻免费视频 | 国产福利在线免费| 久久黄色免费网站| a级毛片黄免费a级毛片| 国产亚洲综合久久| 亚洲AV无码专区在线电影成人| 亚洲欧洲在线播放| 久久精品国产亚洲AV无码娇色| 亚洲色图综合在线| 国产精品亚洲二区在线观看| 在线观看免费亚洲| 国产做床爱无遮挡免费视频| 免费无码精品黄AV电影| 国产精彩免费视频| 麻豆最新国产剧情AV原创免费 | 91精品国产免费| 91免费福利精品国产| 99国产精品免费视频观看|