版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w442863748/article/details/51423559
个人理解递归函数的基本要求就是,函数中调用函数本身,满足特定的条件后返回。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>
#include <sstream>
#include <list>
#include <algorithm>
#include <time.h>
#include <stdarg.h>
#include <queue>
#include <winsock.h>
//头文件引用的较多,有一些和本程序无关
using namespace std;
//递归
void hanoi(int n, char a, char b, char c)
{
if(n == 1)
cout << a << " -> " << c << endl;
else
{
hanoi(n - 1, a, c, b);
cout << a << " -> " << c << endl;
hanoi(n - 1, b, a, c);
}
}
//循环
//void hanoi1(int n, char a, char b, char c)
int main(int argc, char *argv[])
{
hanoi(5, 'A', 'B', 'C');
system("pause");
return 0;
}