Professional Documents
Culture Documents
Name: Saria Mahmood Class: BSCS (3-B) Enrollment: 03-134202-077
Name: Saria Mahmood Class: BSCS (3-B) Enrollment: 03-134202-077
Class: BSCS(3-B)
Enrollment: 03-134202-077
RECURSIVE ALGORITHM:
start
if diskNumber=1
else
HanoiTower (diskNumber-1,start_rod,mid_rod,end_rod)
end if
end function
stop
start
if diskNumber=1
else
HanoiTower (diskNumber-1,start_rod,mid_rod,end_rod)
end if
end function
stop
Move disk 1 from Start rod to Mid rod
Recursion is more efficient approach to solve such problems. A function is modified with new arguments
without any technicality and difficulty. One does not need to create a new function for every updated
information. Recursion is easy to use and more reliable approach to solve hanomi tower problem.
CODE:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n = 3; // Number of disks
TowerOfHanoi(n, "Start", "End", "Mid"); //names of the towers
system("pause");
return 0;
}
OUTPUT: