分治算法之汉诺塔

#include
using namespace std;

void hanoi(int n,char one,char two,char three);

int main()
{
     int m;
     cout<<"输入盘子数:";
     cin>>m;
     hanoi(m,'A','B','C');
}

void move(char x,char y);

void hanoi(int n,char one,char two,char three)
{

     if (n == 1)
     {
           move(one,three);
     }
     else
     {
         hanoi(n-1,one,three,two);
         move(one,three);
         hanoi(n-1,two,one,three);
     }
}


void move(char x, char y)
{
     cout<"<

分治算法之汉诺塔_第1张图片

你可能感兴趣的:(Algorithm)