数据结构:栈与递归(Hanoi塔问题)

void Hanoi( int n, char a, char b, char c )
{
	if ( n == 1 )
	{
		cout << "第"  << n << "块:" << a << "-->" << c << endl;
	}
	else
	{
		Hanoi( n-1, a,  c,  b ); //将n-1块从a经过c移动到b
		cout << "第" << n << "块:" << a << "-->" << c << endl;//将第n块从a直接移到c
		Hanoi( n-1, b, a, c ); //将n-1块从b经过a移动到c
	}
}
    原文作者: 汉诺塔问题
    原文地址: https://blog.csdn.net/s634772208/article/details/45579135
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞