Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- using namespace std;
- void hanoi_towers(int diskCount, char from, char to, char buff) //quantity-число колец, from-начальное положение колец(1-3),to-конечное положение колец(1-3)
- { //buf_peg - промежуточный колышек(1-3)
- if (diskCount!=0)
- {
- hanoi_towers(diskCount-1, from, buff, to);
- cout<<from<<" -> "<<to<<endl;
- hanoi_towers(diskCount-1, buff, to, from);
- cout<<"Кончилась вторая рекурсия"<<endl;
- }
- }
- int main()
- {
- setlocale(LC_ALL,"rus");
- char from='A';
- char to='B';
- char buff='C';
- int N;
- cout<<"Количество дисков:" << endl;
- cin>>N;
- hanoi_towers(N, from, to, buff);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement