We help IT Professionals succeed at work.

# HANOI TOWER

on
396 Views
Do you have hear about one game developed using  C++ programming called HANOI TOWER?. If you did, please give me the idea like algorithm or program structure about that problem.
Comment
Watch Question

## View Solution Only

CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
move(int from, int to, int n){
int other=from^to;
if( n == 0 ){ return; }
move(from,other,n-1);
printf("move %d from %d to %d\n",n,from,to);
move(other,to,n-1);
}
main(){
move(1,2,5);
}

Commented:
ozo's code has the gist of it.

To explain, the idea is that you have 3 poles with a given number of disks, each disk being progresivley larger than the next (stacked like a pyramud).

You have to move all the diskd from the first pole to the third pole while keeping the following rules:

1. You can only move one disk ata time.

2.- You can never place a larger disk on top of a smaller disk.

3.- You can move any disk to any pole in any order.

Commented:
If u want code fragment and description, e-mail me at:
runtime79@hotmail.com

Commented:
Still with the Hanoi tower, what is a C++ program for the algorithm below;
tower(positive integer n, peg i, peg j , peg k)
// move the top n disks on peg i to peg k using peg j
if n=1 then
move top disk on peg i to peg k
else
tower(n-1,i,k,j)
move top diskk on peg i to peg k
tower(n-1,j,i,k)

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
###### Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Connect with Certified Experts to gain insight and support on specific technology challenges including:

• Troubleshooting
• Research
• Professional Opinions
Unlock the solution to this question.

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.