# Yet another Brain Tickler

• 04-25-2002
Unregistered
Yet another Brain Tickler
This one is much more challenging

Write an iterative procedure for tower of hanoi problem.
• 04-25-2002
quzah
Re: Yet another Brain Tickler
Quote:

Originally posted by Unregistered
This one is much more challenging

Write an iterative procedure for tower of hanoi problem.

Here's an even more difficult task! USE A SEARCH ENGINE and find the answer yourself. No one is going to do your ****ing homework for you.

Quzah.
• 04-25-2002
stautze
It is showoff time. Actually this is no trouble for me, I have all of this stuff from when I did it. Here it is, but it has 3 things you have to figure out ....

Code:

```int main(void) {      Move(DISKS,1,3,2);     return 1; } void Move(int count, int start, int finish, int temp) {   int swap;   while (count > 0) {     Move(count - 1, start, temp, finish);   // printf("Move disk %d from %d to %d.\n", count, start, finish);     count--;     swap = ???;     start = ???;     temp = ???;   } }```
• 04-25-2002
quzah
Quote:

Originally posted by stautze
It is showoff time. Actually this is no trouble for me, I have all of this stuff from when I did it. Here it is, but it has 3 things you have to figure out ....

Code:

```void Move(int count, int start, int finish, int temp) {   int swap;   while (count > 0) {     Move(count - 1, start, temp, finish);   // printf("Move disk %d from %d to %d.\n", count, start, finish);     count--;     swap = ???;     start = ???;     temp = ???;   } }```

You realize that this is a recursive function, right?

Quzah.
• 04-25-2002
golfinguy4
I sure hope so.:D
• 04-25-2002
Unregistered
I like how you call your assignment a brain tickler. You should be in marketing!
• 04-26-2002
stautze
>You realize that this is a recursive function, right?

That is technically true, but I think this is still the answer that he is looking for. A truely iterative version is much less elegant and way to bulky.

This is a very clever version that eleminates tail recursion by rearanging the termination condition and repeating the the function with a while statement. I would call it iterative, and your compiler would probably agree with me.
• 04-26-2002
quzah
Sure, but I doubt they want any recursion. Anyway, there are a million hits on Google for Hanoi Towers, so this really is NEVER needed here again.

Quzah.
• 04-27-2002
Shiro
>That is technically true, but I think this is still the answer that he
>is looking for.

I don't think so, he said "Write an iterative procedure".

>A truely iterative version is much less elegant and way to bulky.

That's true, but that was not his homework. Though if he understands recursion, he can use your function by removing the recursion from it.