汉若塔问题的C++程序

代码来自维基教科书:C++ Programming As A Set Of Problems。

程序如下:

 #include <iostream>

 void hanoi(int depth, int from, int to, int alternate)
 {
     if(depth == 0)
     {
         return;
     }
     hanoi(depth-1, from, alternate, to);
     std::cout << "Move ring " << depth << " from pole " << from << " to pole " << to << "." << std::endl;
     hanoi(depth-1, alternate, to, from);
 }

 int main(int argc, char** argv)
 {
     hanoi(4, 1, 2, 3);
     return 0;
 }


你可能感兴趣的:(汉若塔问题的C++程序)