473,387 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

HANOI PROBLEM PLEASE HELP

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()
{ ???????

May 19 '06 #1
3 1935

ka*********@gmail.com wrote:
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

May 19 '06 #2

<ka*********@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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"
May 20 '06 #3
ka*********@gmail.com wrote:
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

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sonia | last post by:
Hi, I have written this code for the Tower of Hanoi problem. I was just wondering if there is any way of optimizing this code ? It's a failry simple code, but I thought that maybe somehow it...
8
by: Constant | last post by:
I need a programe that will deal with the solving of the problem ..i have 3 pegs A, B, C...and I want to move the disk A to disk C using B as auxiliary.At the end all disk should be at peg C in the...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
7
by: ashishnh33 | last post by:
hi.......is there nyone to tell me how to solve the "tower of hanoi" problems
51
by: maloov | last post by:
I have a pretty tough assignment for beginner like me & i'm seeking help please here is the assign In this assignment, you will be guided to complete the program skeleton provided to you in...
3
by: shaghayeghcute2003 | last post by:
I'm currently trying to write The Tower Of Hanoi (http:// illuminations.nctm.org/ActivityDetail.aspx?ID=40) in C#. I have a panel on the form and I draw pegs on the panel inside the form class. I...
6
by: poopsy | last post by:
hi guys cud some1 explain to me the towers of hanoi code, the source code is available evrywhr. i've been trying to understand it bt cant. can some1 plz help me i hav even tried to "trace" it but i...
5
by: seemanikam | last post by:
Can anyone suggest me how to devise an efficient divide-and-conquer algorithm for the Tower-of-Hanoi problem when the disks are colored alternately red and blue, and with the extra rule that no disk...
2
by: sunyboy | last post by:
hi I need a programe "Towers of Hanoi without use recessive function" in c++ Please help. Thanks for your time.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.