汉诺塔非递归算法.我只是将盘子的数量等于2,3的情况代到网上别人给的算法中验证了一下,没有错。并没有证明算法的正确性。算法是否有效,有待大家证明。 T({:Y. A;
f%ZqK_CW
include <iostream> K+dkImkh
#include <stdlib.h> Z66akr
iOPv
% [
#ifdef _WIN32 x?KgEcnw2X
using namespace std; u@}((V
#endif %*e6@Hm
?,%vndI
static void hanoi(int height) )s,L:{<
{ !~04^(
int fromPole, toPole, Disk; }D xXt
int *BitStr = new int[height], //用来计算移动的盘的号码 *rSMD_>
*Hold = new int[height]; //用来存贮当前的盘的位置。hold[0]为第一个盘所在的柱号 :g2?)Er-
char Place[] = {'A', 'C', 'B'}; Wd_bDZQ
int i, j, temp; OZ&J'Y
-LzHCO/7(
for (i=0; i < height; i++) %Z 9<La
{ !e&ZhtTuC
BitStr = 0; `Q1S8i$
Hold = 1; ;{ XKZ}
} A`Z!=og=
temp = 3 - (height % 2); //第一个盘的柱号 ]7O)iq%
int TotalMoves = (1 << height) - 1; ^)rX27!G
for (i=1; i <= TotalMoves; i++) VxLq,$B76
{ (WR&Vt4R