void Hanoi::TowersOfHanoi(int n, int x, int y, int z) { // 把n个碟子从塔x移动到塔y,可借助塔z int num; // 碟子的编号 if (n > 0) { TowersOfHanoi(n-1, x, z, y); num = S[x]->top(); S[x]->pop(); // 从x中移走一个碟子 S[y]->push(num); // 把这个碟子放到y上 std::cout << "Move top disk from tower " << x << " to top of tower" << y << std::endl; TowersOfHanoi(n-1, z, y, x); } }
int main(int argc, char ** argv) { string path = "/Users/andreasfragner/Desktop/"; // TEST STACK DIRECTION (misc.hpp) StackDirection(&argc); // SEARCH testSearch(); // SEEDS srand( int(time(NULL)) ); // TESTS/SPECS BitTest mytest; mytest.run(); // RANDOM testRandom(); // DATA STRUCTURES test_SL(); test_Stack(); test_Queue(); TowersOfHanoi(10); // NUMERICAL test_Numerical(); // PRIMES test_primes(); // SORT test_sort(); // MISC test_misc(); cout << "\n\n\n\n-----------------------------"<<endl; cout << "-----------------------------"<<endl; return 0; }
int main() { TowersOfHanoi(6); return 0; }