Towers of Hanoi: Difference between revisions

Content added Content deleted
(add E example)
(Added C++)
Line 37: Line 37:
return moves
return moves
end hanoi
end hanoi


==[[C plus plus|C++]]==
[[Category:C plus plus]]
'''Compiler:''' [[GCC]]

void move(int n, int from, int to, int via) {
if (n == 1) {
std::cout << "Move disk from pole " << from << " to pole " << to << std::endl;
} else {
move(n - 1, from, via, to);
move(1, from, to, via);
move(n - 1, via, to, from);
}
}




==[[E]]==
==[[E]]==