towers of hanoi
Post on 06-Apr-2016
214 Views
Preview:
DESCRIPTION
C++ Program
TRANSCRIPT
#include <iostream>
using namespace std;
void hanoi(int n, string source, string destination, string help);
main() { int disks; cout << "How many disks? "; cin >> disks; hanoi(disks, "Pole 1", "Pole 2", "Pole 3"); system("PAUSE > NUL");}
void hanoi(int n, string source, string destination, string help) { if (n == 1) { cout << "Move 1 disk from " << source << " to " << destination << endl; } else { hanoi(n - 1, source, help, destination); cout << "Move 1 disk from " << source << " to " << destination << endl; hanoi(n - 1, help, destination, source); }}
top related