Tower Of Hanoi Program In C Using Graphics With Swift

Posted by admin
Active1 year, 3 months ago

May 22, 2014  Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time. 2) Each move consists.

Can someone please tell me how the 1000V gets its serial number? I have a few I need to register the license PAK and they all seem to have the same serial number. I posted this in two areas, not sure where 1KV questions need to go. Solved: Can someone please tell me how the 1000V gets its serial number? I have a few I need to register the license PAK and they all seem to have the same serial number. Nexus 1000v serial number.

I am working on an exercise in a book which asks us to solve the Towers of Hanoi problem using recursive methods. I have come to a solution, but from what I gather after browsing the Internet when done is that my solution may not be correct. Does anyone know a better/different way to solve the problem? And does anyone have nay suggestions for improvements. (Btw, the out put is correct. It is only supposed to tell from which tower to another pegs are moving, not specifically which pegs)

Here is the code:

Is this method qualified as recursion?

E.O.E.O.
3645 gold badges12 silver badges23 bronze badges

5 Answers

To answer your question: yes, that is qualified as recursion. Any time a function calls itself, it is recursion.

With that being said, your code can be trimmed down substantially:

riwalkriwalk
12.4k5 gold badges40 silver badges65 bronze badges

It's easiest if you look at the problem recursively:

To move N discs from A to B (using C):

  1. if (N > 1) move N-1 discs from A to C (using B)
  2. move one disc from A to B
  3. if (N > 1) move N-1 discs from C to B (using A)

For any given call, whichever peg is not the source or the destination is the ancillary.

To answer your actual question: yes, your solution appears to be recursive, though a bit more complex than really necessary.

Jerry CoffinJerry Coffin
399k58 gold badges497 silver badges940 bronze badges
Tower Of Hanoi Program In C Using Graphics With Swift

Every recursion method has 3 steps

1) A check condition2) Return value when check condition is satisfied.3) A call to method itself

@Stargazer712 solution is perfect.

NickNick
1,2103 gold badges16 silver badges29 bronze badges
Umair A R MughalUmair A R Mughal
Tower of hanoi program in c using graphics with swift number
isaac kargarisaac kargar

Not the answer you're looking for? Browse other questions tagged c++recursiontowers-of-hanoi or ask your own question.

Active6 years ago

I just wrote a program for the Tower of hanoi problem in C using recursion.But what stresses is how to manage the complexity of such a problem when the total no. of disks are like 4,5 and whats the logic in the two TOH() recursive calls in the method itself. The program is as follows

Zaid KhanTower of hanoi program in c using graphics with swift freeZaid Khan
3972 gold badges4 silver badges21 bronze badges

closed as unclear what you're asking by Ed Heal, A5C1D2H2I1M1N2O1R2T1, hjpotter92, Jens Gustedt, Basile StarynkevitchSep 8 '13 at 8:05

How To Program In C

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Tower Of Hanoi Program In C Using Graphics With Swift Code

1 Answer

Although your program works fine. May be this is what you are looking for:-

Rahul TripathiRahul Tripathi
134k21 gold badges191 silver badges263 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged crecursion or ask your own question.