HANOI PROBLEM PLEASE HELP

K

kamvisiouma

Hi there, I'm fresh in learning c++ and I have to solve an exercise
with hanoi and my problem is that I'm running out of time!
The exercise is this, and I have to complete the ???

#include<stdio.h>

#define DISK_NUMBER 4

// There are 3 towers represents 3 stacks
// The names of the disks are represented by numbers (1,2,3,...,n)
// That means that 2 is smaller disk from 4 etc
// 0 shows absense of disk

// 2 dimensions table for 3 stack - towers

int tower[3][DISK_NUMBER];

//Saving the number of transfers

int transfer_number= 0;

/* dhlwseis synarthsewn*/

void Towers();
void Insert(int Tower, int disk);
int Delete(int Tower);
void moveTower(int DISK_NUMBER, int initial, int final , int
middle);
void moveDisk(int initial, int final);
void printTowers();

int main(void)

{
Towers();
printf("\n\n\t\tHANOI
TOWERS\n------------------------------------------

------\n\t\t at the beginning\n");
printTowers();
printf("\n\n\-------------------------------------------------\n");
moveTower(DISK_NUMBER, 0 , 2 , 1);
printf("\n\n The number of transfers is : %d \n",

tranfer_number);
return 0;

}

void Towers()
{ ??????

}

void Insert(int tower, int disk)
{ ??????

}

int Delete(int tower)
{ ??????

}

void moveTower(int DISK_NUMBER, int initial, int final , int
middle)
{

if( DISK_NUMBER == 0)// when we reach base
return;

int temporaryDisk = destination;

// transfer smaller disk from initial tower to the middle usin the
final tower

moveTower(DISK_NUMBER-1, initial, middle, temporaryDisk);

//transfer bigger disk

moveDisk(initial, final);

temporaryDisk = initial;

// transfer the rest of the disks from the middle tower to the final
using initial tower

moveTower(DISK_NUMBER-1, middle, final, temporaryDisk);

}

void moveDisk(int initial, int final)
{ ???????

}

void printTowers()
{ ???????
 
P

peter koch

Hi there, I'm fresh in learning c++ and I have to solve an exercise
with hanoi and my problem is that I'm running out of time!
The exercise is this, and I have to complete the ???

Hi! I'm happy to help you. There are two problems here - the first one
related to your code. I'm snipping some of it:

[snip]
void Towers()
{ ??????

}

This code is illegal, so you'd have to replace those questionmarks with
something legal.

The second problem relates to this forum: we do not do others homework.
go to e.g. comp.cheatwithhomework.lang.c++ and remember to bring your
VISA.

/Peter
 
J

Jim Langston

Hi there, I'm fresh in learning c++ and I have to solve an exercise
with hanoi and my problem is that I'm running out of time!
The exercise is this, and I have to complete the ???

#include<stdio.h>

#define DISK_NUMBER 4

// There are 3 towers represents 3 stacks
// The names of the disks are represented by numbers (1,2,3,...,n)
// That means that 2 is smaller disk from 4 etc
// 0 shows absense of disk

// 2 dimensions table for 3 stack - towers

int tower[3][DISK_NUMBER];

//Saving the number of transfers

int transfer_number= 0;

/* dhlwseis synarthsewn*/

void Towers();
void Insert(int Tower, int disk);
int Delete(int Tower);
void moveTower(int DISK_NUMBER, int initial, int final , int
middle);
void moveDisk(int initial, int final);
void printTowers();

int main(void)

{
Towers();
printf("\n\n\t\tHANOI
TOWERS\n------------------------------------------

------\n\t\t at the beginning\n");
printTowers();
printf("\n\n\-------------------------------------------------\n");
moveTower(DISK_NUMBER, 0 , 2 , 1);
printf("\n\n The number of transfers is : %d \n",

tranfer_number);
return 0;

}

void Towers()
{ ??????

}

void Insert(int tower, int disk)
{ ??????

}

int Delete(int tower)
{ ??????

}

void moveTower(int DISK_NUMBER, int initial, int final , int
middle)
{

if( DISK_NUMBER == 0)// when we reach base
return;

int temporaryDisk = destination;

// transfer smaller disk from initial tower to the middle usin the
final tower

moveTower(DISK_NUMBER-1, initial, middle, temporaryDisk);

//transfer bigger disk

moveDisk(initial, final);

temporaryDisk = initial;

// transfer the rest of the disks from the middle tower to the final
using initial tower

moveTower(DISK_NUMBER-1, middle, final, temporaryDisk);

}

void moveDisk(int initial, int final)
{ ???????

}

void printTowers()
{ ???????

STFW. Been done many times. We're not going to do your homework for you.
But if you learn to STFW you'll learn to find aid (if not code). Yes, it's
called "tower of hanoi"
 
?

=?ISO-8859-1?Q?Martin_J=F8rgensen?=

Hi there, I'm fresh in learning c++ and I have to solve an exercise
with hanoi and my problem is that I'm running out of time!

No, your problem is that you're too lazy to put just a little work in
trying to solve the problem.

At least you could have tried to put something meaningful in the places
where you wrote ??????????????? and you didn't made any progress since
the time he handed out the exercise. At this time, you should have had
some basic knowledge about classes/functions etc, but you don't show
that. Just show us that you can actually think yourself and you'll get
much more help.


Best regards / Med venlig hilsen
Martin Jørgensen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top