Solved

Towers of Hanoi

Posted on 1997-05-20
1
496 Views
Last Modified: 2008-03-17
I need to get the code for the towers of hanoi in c++
I have been trying for days to figure it out.
"please help"
0
Comment
Question by:denver
1 Comment
 
LVL 5

Accepted Solution

by:
yonat earned 20 total points
ID: 1163587
#include <iostream.h>

void Hanoi(char source, char temp, char destination, int n)
/* This functions takes a tower of n disks and moves from peg  */
/* 'source' to peg 'destination'.  Peg 'temp' may be used      */
/* temporarily.                                                */
{
        if (n>0)
        {
        Hanoi (source, destination, temp, n-1);
        cout << "Move disk "<<< n << " from peg " << source <<
                " to peg " << destination << ".\n";
        Hanoi ( temp, source, destination, n-1);
        }
}

main()
{       int n;
        cout << "Enter the number of disks: ";
        cin >> n;
        cout << '\n';
        Hanoi('A','B','C',n);
}


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Implementing a ResolveEventHandler in C++ 13 115
Writing a parser for java language 4 71
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 82
thread-safe code in c++ 2 84
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now