// // test of Towers of Hanoi routine // // Described in Chapter 3 of // Data Structures in C++ using the STL // Published by Addison-Wesley, 1997 // Written by Tim Budd, budd@cs.orst.edu // Oregon State University // # include void Hanoi (int n, char a, char b, char c) // move n disks from tower a to tower b, using tower c { if (n == 1) { // can move smallest disk directly cout << "move disk from tower " << a << " to " << b << endl; } else { // first move all but last disk to tower c Hanoi (n-1, a, c, b); // then move one disk from a to b cout << "move disk from tower " << a << " to " << b << endl; // then move all disks from c back to b Hanoi (n-1, c, b, a); } } void main() { Hanoi(5, 'a', 'b', 'c'); }