Friday, July 31, 2009

Hi! everyone!!! i have a code tower of hanoi in c++.can some one plss .help me.?

the code is using recursion. can someone pls tell me how it's working or change the code to normal code without recursion and class or stack. plss help me code is as follows:---








//prog to print the solution of TOWERS OF HANOI





#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt; //for clrscr()





void hanoi(int n, char A, char B, char C)


{


if(n%26gt;0)


{


hanoi(n-1,A,C,B);


cout%26lt;%26lt;"\nMove disc " %26lt;%26lt;n%26lt;%26lt;"from tower"%26lt;%26lt; A%26lt;%26lt;"to tower"%26lt;%26lt; B;


hanoi(n-1,C,B,A);


}


return;


}





void main()


{


int n;


clrscr();





cout%26lt;%26lt;"Enter the number of discs : ";


cin%26gt;%26gt;n; //input





cout%26lt;%26lt;"\nThe solution to Tower of Hanoi is:- \n";


hanoi(n,'L','R','C');





getch();


}











pls help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

Hi! everyone!!! i have a code tower of hanoi in c++.can some one plss .help me.?
Tower of hanoi solution involves recursive tasks. That is why most of the implementations are done using recursion.





I works as, we 1st places the the biggest Coin in the destination peg and our remaining task is to place (n-1) Coins on top of the nth one.
Reply:http://www.cut-the-knot.org/recurrence/h...


No comments:

Post a Comment