I Fumble with a iterative c++ TOH solution. I think there has to be a general theorem that transfers recursive into iteratives. While here I just mimic the recursive. It is def. including 1 or 2-3 linked lists. Linked list are dis-encouraged by Bjarne, but they cover have some special needs. Anyway it includes a integer series that acts as a "selector".
step 0. is to create the selector and LL A, while LL C is empty. I have already. While like to prog the selector as a lambda function somehow. Have not still.
presets :
XX : move SRC TO DEST |
SA : SWAP DEST, AND TMP |
SB : SWAP TMP AND SRC |
It looks like it can be done in 5 steps.
- read the next selector element
- copy XX from LL A to LL C. But stop if summa iterations equ 1,3, 7 etc. depending on N.
- read the next selector element
- copy XX from LL A to LL C.
- swap SB'wize LL A's (selector value) -1 , the remaining elements in LL A swap SA'wize
repeat 1 .. 5. Voila ! LL C reads all the moves.