阿摩線上測驗 登入

申論題資訊

試卷:108年 - 桃園高中 108 學年度第 1 次教師甄選資訊科#75927
科目:教甄◆資訊科技概論專業(電腦科)
年份:108年
排序:0

申論題內容

6. Tower of Hanoi with Adjacency Requirement: (each 2 points) Suppose that in addition to the requirement that they never move a larger disk on top of a smaller one, the priests who move the disks of the Tower of Hanoi are also allowed only to move disks one by one from one pole to an adjacent pole. 



Assume poles A and C are at the two ends of the row and pole B is in the middle, if a single disk is to be moved from pole A to pole C (using pole B), then moving the disk directly from A to C is not allowed. The disk must be first transferred to pole B and then to pole C.(A->B,B->C) 

The following function shows the solution for Tower of Hanoi with Adjacency Requirement. Please fill the blanks, and derive the time complexity of the program.

 /* note: move n disks from pole "from" to pole "to" using pole "aux" for auxiliary, where pole "from" is not adjacent to pole "to". */
 void HanoiWithAdj(char from, char aux, char to, int n){
5ccbe7eeef7c9.jpg