Advertisement
Proff_Ust

Hanoy

May 14th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. using namespace std;
  4.  
  5. void hanoi_towers(int diskCount, char from, char to, char buff)   //quantity-число колец, from-начальное положение колец(1-3),to-конечное положение колец(1-3)
  6. {                                                         //buf_peg - промежуточный колышек(1-3)
  7.     if (diskCount!=0)
  8.     {
  9.         hanoi_towers(diskCount-1, from, buff, to);
  10.         cout<<from<<" -> "<<to<<endl;
  11.         hanoi_towers(diskCount-1, buff, to, from);
  12.         cout<<"Кончилась вторая рекурсия"<<endl;
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     setlocale(LC_ALL,"rus");
  19.     char from='A';
  20.     char to='B';
  21.     char buff='C';
  22.     int N;
  23.     cout<<"Количество дисков:" << endl;
  24.     cin>>N;
  25.     hanoi_towers(N, from, to, buff);
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement