• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            just Programme

            編程是個很長的路程
            posts - 0, comments - 2, trackbacks - 0, articles - 2
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            使用單向循環鏈表實現約瑟夫問題

            Posted on 2006-05-13 16:07 SmallTalk 閱讀(3688) 評論(1)  編輯 收藏 引用 所屬分類: C++小程序

            //Jose.cpp----使用單向循環鏈表實現約瑟夫問題
            //問題描述:n個人手拉手排成一個環,從第一個人開始數,每數到第m個人,第m個人出列,從下一人重新計數重新數,求全部出列后他們的出列順序
            #include <iostream.h>
            struct jose
            {
            ?int data;
            ?int no;
            ?struct jose * next;
            };

            int main()
            {
            ?struct jose *head,*p_curent,*p_find;
            ?int n,m;
            ?cout << "Please enter the total of numbers (n):";
            ?cin >> n;
            ?cout << "Please enter the counter number (m):";
            ?cin >> m;
            ?
            ?//初始化鏈表
            ?head=p_curent=new jose;//標記首表元地址,即頭指針
            ?head->no=1;
            ?cout << "Please enter the first number :";
            ?cin >>head->data;
            ?//形成其余的n-1表元
            ?cout << "Please enter last numbers :"<<endl;
            ?for (int i=2;i<=n;i++)
            ?{
            ??p_curent->next=new jose;
            ??p_curent=p_curent->next;
            ??cin >> p_curent->data;
            ??p_curent->no=i;
            ?}//end for
            ?p_curent->next=head;//尾指針指向頭指針,形成環,到這完成初始化鏈表

            ?//開始查詢,第M個人出列,并輸出
            ?cout << "Now : The? numbers of who will quit the cycle in turn are:"<<endl;
            ?while (n)//全部出列后結束循環
            ?{
            ??//掠過m-1個表元
            ??for (int j=1;j<m;j++)
            ???p_curent=p_curent->next;//end?for
            ??//找到第M個人
            ??p_find=p_curent->next;
            ??//從表中刪除第m個人,并輸出第m個人
            ??p_curent->next=p_find->next;
            ??cout << p_find->data<<endl;
            ??//釋放第m個表元占用的空間
            ??delete p_find;
            ??n--;
            ?}
            ?//end while
            ?
            ?return 0;
            }

            Feedback

            # re: 使用單向循環鏈表實現約瑟夫問題  回復  更多評論   

            2010-04-01 23:52 by 郝竹林
            你這個程序不算完美 看看我寫的 http://blog.renren.com/blog/316635779/454822169
            国产2021久久精品| 久久久久久久久久免免费精品| 久久激情五月丁香伊人| 久久精品国产精品亚洲艾草网美妙| 亚洲欧美国产日韩综合久久| 久久99久久99精品免视看动漫| 久久青青草原综合伊人| 伊人久久大香线蕉综合热线| 久久国产色AV免费看| 久久久无码精品亚洲日韩蜜臀浪潮 | 国产精品久久久久无码av| 香蕉久久AⅤ一区二区三区| 久久综合给合久久国产免费| 国内精品久久久久久久久| 久久精品国产一区| 久久99国产综合精品女同| 无码乱码观看精品久久| 久久99国产亚洲高清观看首页| 日韩美女18网站久久精品| 色综合久久久久网| 麻豆成人久久精品二区三区免费| 久久人人爽人人爽人人片AV麻豆 | 伊人久久大香线蕉av不卡| 久久只有这里有精品4| 精品久久久久久国产三级| 久久亚洲AV成人无码电影| 久久这里都是精品| 久久性生大片免费观看性| 一本久久a久久精品综合夜夜| AAA级久久久精品无码区| 久久精品中文字幕久久| 国内精品九九久久精品| 久久伊人五月丁香狠狠色| 亚洲国产精品无码久久一线| 精品久久久久久中文字幕人妻最新| 亚洲综合久久久| 久久天天躁狠狠躁夜夜avapp| 亚洲人AV永久一区二区三区久久| 久久se精品一区二区影院| 狠狠精品久久久无码中文字幕| 精品久久久久久无码人妻热 |