Foros aprenderaprogramar.com
Aprender a programar => Aprender a programar desde cero => Mensaje iniciado por: sandra84 en 10 de Abril 2013, 09:50
-
HOLA:
NECESITO AYUDA PARA REALIZAR UN DIAGRAMA DE FLUJO DE LAS TORRES DE HANOI CON 5 DISCOS, PRETENDO HACER LO CON IF
-
¿A qué te refieres cuando dices que pretendes hacerlo con IF? ¿Te refieres a una herramienta para crear diagramas de flujo o a usar condicionales de tipo if ... then (si ocurre esto ... entonces ...)?
-
Y otra cosa: el problema se puede resolver con recursividad o con iteración ¿sabes de qué manera lo tienes o quieres enfocar?
-
asi es perdon, con la condicion IF, realmente no se como hacerlo estoy en eso, estoy en pruebas de escritorio usando arreglos, ah se me hacen difíciles :o :o los diagramas de flujo!!
-
Pienso que la información en esta página te puede ser útil: http://hanoitower.mkolar.org/algo.html ((incluso te da el código en c)
Hay diversos algoritmos pero si no quieres usar recursión hay una parte en la que explica cómo hacerlo con condicionales IF, donde dice:
I have formulated the following iterative algorithm for disk transfers, that can be easily converted into computer code:
Initial move:
Disk 1 is moved to peg 3 if n is odd, and to peg 2 if n is even.
Subsequent moves depend on the parity of the disk transferred in the immediately preceding move:
If its parity is even, the destination peg in the next move will remain the same, and the next disk will be transferred there from the peg that was not involved in the immediately preceding move (this disk will be placed on top of the previously transferred even disk, and therefore must be odd)
If its parity is odd, the next transfer will be between pegs that are both different from the immediately preceding destination peg, and the direction of the move is such that a smaller disk is placed on top of a larger one.
In this algorithm it is assumed that the bases of the towers are all assigned the number n+1, and are treated as "disks" larger than all others. In this way, care is taken automatically of an empty peg.
A partir de esta idea se podría crear el código y el diagrama de flujo.