正在阅读:C++数据结构学习:递归(2.2)C++数据结构学习:递归(2.2)

2004-02-14 09:34 出处:PConline 作者:happycock/CSDN 责任编辑:linjixiong
if (!m) { source = ns.pop(); target_m = ns.pop();   m = needle[source].movenum(ns.pop()); }//障碍盘子搬走后,回到原来的当前柱   if (m % 2) target = target_m; else target = 3 - source - target_m;//规律1的实现   if (needle[source].top() < needle[target].top())//当前柱顶端盘子可以搬动时,移动盘子   {   disk = needle[source].top();m--;   cout << disk << " move " << (char)(source + 0x41) << " to "<< (char)(target + 0x41) << endl;//显示搬动过程   needle[target].push(needle[source].pop());//在目标柱上面放盘子   if (disk == n) { source = 1 - source; target_m = 2; m = --n; }规律3的实现   }   else//规律2的实现   {   ns.push(needle[source][needle[source].size() - m]);   ns.push(target_m); ns.push(source);   m = needle[target].movenum(needle[source].top());   target_m = 3 - source - target; source = target;   }   }     }
键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品