Re: [理工] 演算法-遞迴

看板Grad-ProbAsk作者 (奈何上天造化弄人?)時間7年前 (2018/08/14 02:16), 編輯推噓1(100)
留言1則, 1人參與, 7年前最新討論串2/2 (看更多)
※ 引述《rex51920594 (rex51920594)》之銘言: : The following recursive program segment is written in C language. : Write the output if it is called with the instruction xbox (3, ‘A’, ‘B’, : ‘C’). : void xbox (int n, char x, char y, char z) 稱xbox : { : if (n > 0 ) { : printf(“%c %c %c \n”, x, y, z); : xbox (n-1 , x, z, y); 稱xbox_1 : xbox (n-1 , y, x, z); 稱xbox_2 : } : } 以上那種稱呼只是方便你了解 : 解: : n = 3 A B C xbox(3, 'A', 'B', 'C')中的printf : n = 2 A C B xbox_1(3-1, 'A', 'C', 'B')中的printf =xbox(2, 'A', 'C', 'B')中的printf : n = 1 A B C xbox_1(2-1, 'A', 'B', 'C')中的printf =xbox(1, 'A', 'B', 'C')中的printf : n = 1 C A B xbox_2(2-1, 'C', 'A', 'B')中的printf =xbox(1, 'C', 'A', 'B')中的printf : n = 2 B A C xbox_2(3-1, 'B', 'A', 'C')中的printf =xbox(2, 'B', 'A', 'C')中的printf : n =1 B C A xbox_1(2-1, 'B', 'C', 'A')中的printf =xbox(1, 'B', 'C', 'A')中的printf : n =1 A B C xbox_2(2-1, 'A', 'B', 'C')中的printf =xbox(1, 'A', 'B', 'C')中的printf 程式中又沒有要列印n 回答怎麼能把n = x寫出來? 我要是閱卷者,第一個就給你打叉 : ---------------- : 剛碰演算法,有點不太懂這如何做出來的 : n = 3 A B C : n = 2 A C B ←到這裡都還懂 : 下面就想破頭也想不出道理... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.118.92 ※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1534184194.A.E3A.html

08/14 20:13, 7年前 , 1F
感謝!答題會記住這點的
08/14 20:13, 1F
文章代碼(AID): #1RSSi2uw (Grad-ProbAsk)
討論串 (同標題文章)
文章代碼(AID): #1RSSi2uw (Grad-ProbAsk)