This one is much more challenging
Write an iterative procedure for tower of hanoi problem.
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.Originally posted by Unregistered
This one is much more challenging
Write an iterative procedure for tower of hanoi problem.
Quzah.
Hope is the first step on the road to disappointment.
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 = ???; } }
You realize that this is a recursive function, right?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 = ???; } }
Quzah.
Hope is the first step on the road to disappointment.
I sure hope so.
I like how you call your assignment a brain tickler. You should be in marketing!
>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.
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.
Hope is the first step on the road to disappointment.
>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.