⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hanoirecursive.cpp

📁 《数据结构、算法与应用》从C++语言应用角度列举了要点
💻 CPP
字号:
// Recursive Towers of Hanoi

#include <iostream>

using namespace std;

void towersOfHanoi(int n, int x, int y, int z)
{// Move the top n disks from tower x to tower y.
 // Use tower z for intermediate storage.
   if (n > 0)
   {
      towersOfHanoi(n-1, x, z, y);
      cout << "Move top disk from tower " << x 
           << " to top of tower " << y << endl;
      towersOfHanoi(n-1, z, y, x);
   }
}

void main(void)
{
   cout << "Moves for a three disk problem are" << endl;
   towersOfHanoi(3,1,2,3);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -