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.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

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)

void

move_tower(int n, post_t source, post_t dest, post_t tmp)

{

if (num_disks == 1) {

move1_disk(max_disks, source, dest);

display_posts(max_disks);

} else {

move_tower(max_disks, num_disks - 1, source, tmp, dest);

move1_disk(max_disks, source, dest);

display_posts(max_disks);

move_tower(max_disks, num_disks - 1, tmp, dest, source);

}

}

You can place move tower inside a class, say x, in which case you would change the (untested) code to:

// x.h

typedef int post_t;

class x {

private:

int max_disks;

public:

x(); // write default constructor to define number of disks to a constant value, say 5.

x(int numdisks){ this.max_disks = numdisks; }

void move_tower( int n, post_t source, post_t dest, postT tmp);

void move1_disk(max_disks, source, dest);

void display_posts(max_disks);

// x.cpp

#include "x.h"

x :: move_tower(int n, post_t source, post_t dest, post_t tmp)

{

if (num_disks == 1) {

x.move1_disk(max_disks, source, dest);// write code to increment dest and decrement source by 1

x.display_posts(max_disks)

} else {

x.move_tower(max_disks, num_disks - 1, source, tmp, dest);

move1_disk(max_disks, source, dest);

display_posts(max_disks);

x.move_tower(max_disks, num_disks - 1, tmp, dest, source);

}

}

// Place code for missing methods here.

Or just leave it as is in C and call it from main() since C code is perfectly valid in C++.

| | |

| | |

***** | |

******* * ***

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C++

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

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);

}