久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='xi9uZ'></small><noframes id='xi9uZ'>

      <bdo id='xi9uZ'></bdo><ul id='xi9uZ'></ul>
  1. <tfoot id='xi9uZ'></tfoot>
  2. <legend id='xi9uZ'><style id='xi9uZ'><dir id='xi9uZ'><q id='xi9uZ'></q></dir></style></legend>
    <i id='xi9uZ'><tr id='xi9uZ'><dt id='xi9uZ'><q id='xi9uZ'><span id='xi9uZ'><b id='xi9uZ'><form id='xi9uZ'><ins id='xi9uZ'></ins><ul id='xi9uZ'></ul><sub id='xi9uZ'></sub></form><legend id='xi9uZ'></legend><bdo id='xi9uZ'><pre id='xi9uZ'><center id='xi9uZ'></center></pre></bdo></b><th id='xi9uZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xi9uZ'><tfoot id='xi9uZ'></tfoot><dl id='xi9uZ'><fieldset id='xi9uZ'></fieldset></dl></div>

      了解遞歸以生成排列

      Understanding Recursion to generate permutations(了解遞歸以生成排列)
          <i id='bT9Jj'><tr id='bT9Jj'><dt id='bT9Jj'><q id='bT9Jj'><span id='bT9Jj'><b id='bT9Jj'><form id='bT9Jj'><ins id='bT9Jj'></ins><ul id='bT9Jj'></ul><sub id='bT9Jj'></sub></form><legend id='bT9Jj'></legend><bdo id='bT9Jj'><pre id='bT9Jj'><center id='bT9Jj'></center></pre></bdo></b><th id='bT9Jj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bT9Jj'><tfoot id='bT9Jj'></tfoot><dl id='bT9Jj'><fieldset id='bT9Jj'></fieldset></dl></div>

            <bdo id='bT9Jj'></bdo><ul id='bT9Jj'></ul>

              1. <small id='bT9Jj'></small><noframes id='bT9Jj'>

                <tfoot id='bT9Jj'></tfoot>

              2. <legend id='bT9Jj'><style id='bT9Jj'><dir id='bT9Jj'><q id='bT9Jj'></q></dir></style></legend>
                  <tbody id='bT9Jj'></tbody>
                本文介紹了了解遞歸以生成排列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我發現遞歸,除了像階乘這樣非常直接的遞歸,非常難以理解.以下代碼段打印字符串的所有排列.誰能幫我理解一下.正確理解遞歸的方法是什么.

                I find recursion, apart from very straight forward ones like factorial, very difficult to understand. The following snippet prints all permutations of a string. Can anyone help me understand it. What is the way to go about to understand recursion properly.

                void permute(char a[], int i, int n)
                {
                   int j;
                   if (i == n)
                     cout << a << endl;
                   else
                   {
                       for (j = i; j <= n; j++)
                       {
                          swap(a[i], a[j]);          
                          permute(a, i+1, n);
                          swap(a[i], a[j]);
                       }
                   }
                } 
                
                int main()
                {
                   char a[] = "ABCD";
                   permute(a, 0, 3);
                   getchar();
                   return 0;
                }
                

                推薦答案

                PaulR 提出了正確的建議.您必須通過手工"(使用任何您想要的工具——調試器、文件、記錄函數調用和某些點的變量)來運行代碼,直到你理解它.有關代碼的解釋,我會向您推薦 quasiverse 的優秀答案.

                PaulR has the right suggestion. You have to run through the code by "hand" (using whatever tools you want - debuggers, paper, logging function calls and variables at certain points) until you understand it. For an explanation of the code I'll refer you to quasiverse's excellent answer.

                也許這個調用圖的可視化用稍微小一點的字符串使它的工作原理更加明顯:

                Perhaps this visualization of the call graph with a slightly smaller string makes it more obvious how it works:

                該圖是使用 graphviz 制作的.

                The graph was made with graphviz.

                // x.dot
                // dot x.dot -Tpng -o x.png
                digraph x {
                rankdir=LR
                size="16,10"
                
                node [label="permute("ABC", 0, 2)"] n0;
                 node [label="permute("ABC", 1, 2)"] n1;
                  node [label="permute("ABC", 2, 2)"] n2;
                  node [label="permute("ACB", 2, 2)"] n3;
                 node [label="permute("BAC", 1, 2)"] n4;
                  node [label="permute("BAC", 2, 2)"] n5;
                  node [label="permute("BCA", 2, 2)"] n6;
                 node [label="permute("CBA", 1, 2)"] n7;
                  node [label="permute("CBA", 2, 2)"] n8;
                  node [label="permute("CAB", 2, 2)"] n9;
                
                n0 -> n1 [label="swap(0, 0)"];
                n0 -> n4 [label="swap(0, 1)"];
                n0 -> n7 [label="swap(0, 2)"];
                
                n1 -> n2 [label="swap(1, 1)"];
                n1 -> n3 [label="swap(1, 2)"];
                
                n4 -> n5 [label="swap(1, 1)"];
                n4 -> n6 [label="swap(1, 2)"];
                
                n7 -> n8 [label="swap(1, 1)"];
                n7 -> n9 [label="swap(1, 2)"];
                }
                

                這篇關于了解遞歸以生成排列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)

                    <i id='pBI62'><tr id='pBI62'><dt id='pBI62'><q id='pBI62'><span id='pBI62'><b id='pBI62'><form id='pBI62'><ins id='pBI62'></ins><ul id='pBI62'></ul><sub id='pBI62'></sub></form><legend id='pBI62'></legend><bdo id='pBI62'><pre id='pBI62'><center id='pBI62'></center></pre></bdo></b><th id='pBI62'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pBI62'><tfoot id='pBI62'></tfoot><dl id='pBI62'><fieldset id='pBI62'></fieldset></dl></div>
                      <tbody id='pBI62'></tbody>

                      • <bdo id='pBI62'></bdo><ul id='pBI62'></ul>

                        <small id='pBI62'></small><noframes id='pBI62'>

                        <legend id='pBI62'><style id='pBI62'><dir id='pBI62'><q id='pBI62'></q></dir></style></legend>

                          <tfoot id='pBI62'></tfoot>

                        1. 主站蜘蛛池模板: 欧美一区二区三区日韩 | 大久| 亚洲精品日韩在线观看 | 精品成人免费视频 | 日本视频一区二区三区 | 欧美精品一二三 | 国产精品久久久久久 | 999精品在线观看 | 日本爱爱 | 日韩视频一区 | 99热播精品| 欧美激情精品久久久久久 | 黄网址在线观看 | 国产成人99av超碰超爽 | 日韩欧美在线视频 | 一级看片 | 免费观看的av毛片的网站 | 天天天天操 | 亚洲精品久久久蜜桃 | 91免费在线播放 | 91玖玖| 久久福利 | 91tv在线观看 | 中文字幕第十一页 | 亚洲网站在线观看 | 日韩精品久久久 | 亚洲日本欧美日韩高观看 | 国产精品久久久久久久久久 | 伊人看片| 亚洲一区| 日韩精品一区二区三区中文在线 | 亚洲成人一级 | 先锋资源网 | 中文字幕亚洲免费 | 久久久久av| 亚洲免费三级 | 久久伊人精品一区二区三区 | 九九久久国产 | 亚洲欧美中文字幕在线观看 | 91国内在线观看 | 色综合一区二区三区 |