![]() ![]() Void towersOfHanoi(int disks, Tower* t1, Tower* t2, Tower* t3) String orderedTowers(Tower*, Tower*, Tower*) Void towersOfHanoi(int, Tower*, Tower*, Tower*) String output = "Tower " + this->name + ": " It includes a Tower class that I made to be able to print the three towers onto the console. I believe that I have the gist of the loop, and I'm able to print out what moved as well as a simple text graphic of the 3 towers. Using if check we can check for the base case.So, I'm trying my hand at making a recursive function to solve the Towers of Hanoi. The parameters we will pass to the function will be, as previously noted number of disks, and the three towers. Implementation of algorithm in Python We start by defining the function and its parameters. The recursive calls should dismount the calls to itself all up to the base case, which is where n=1. The total number of steps should be at minimum 2^n-1, which can be utilized in order to control the validity of the algorithm. Whenever the disk moves, algorithm should notify the user, ultimately giving the print-out of the steps taken in order to solve the puzzle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |