#include
“
iostream
“
using
namespace
std;
int
k
=
0
;
void
hanoi(
int
m ,
char
a ,
char
b,
char
c)
{
if
(m
==
1
)
{
k
++
;
printf(
“
%c->%c
“
,a , c);
return
;
}
hanoi(m
–
1
, a, c , b);
printf(
“
%c->%c
“
,a , c);
k
++
;
hanoi(m
–
1
, b, a, c);
}
int
main()
{
int
n;
char
x,y,z;
while
(cin
>>
n)
{
x
=
‘
A
‘
;y
=
‘
B
‘
; z
=
‘
C
‘
;
cout
<<
“
移动过程:——->
“
<<
endl;
hanoi( n , x, y, z );
cout
<<
endl;
cout
<<
“
移动次数:—–>
“
<<
endl;
cout
<<
k
<<
endl;
}
return
0
;
}
汉诺塔(数据结构课本实现)
原文作者: 汉诺塔问题
原文地址: https://blog.csdn.net/cskiller123/article/details/7913091
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/cskiller123/article/details/7913091
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。