Ejemplo n.º 1
0
void MoveDisks(int nDiskNum, char chSourcePole, char chTargetPole, char chMidPole)
{
	if (nDiskNum == 1)
		printf("%c -> %c\n", chSourcePole, chTargetPole);
	else
	{
	 	MoveDisks(nDiskNum-1, chSourcePole, chMidPole, chTargetPole);
		printf("%c -> %c\n",chSourcePole,chTargetPole);
		MoveDisks(nDiskNum-1, chMidPole,  chTargetPole , chSourcePole);
	}
}
Ejemplo n.º 2
0
 void MoveDisks(int n, Tower d, Tower buffer)
 {
     if( n > 0 ) {
         // put n-1 elements to the buffer Tower
         MoveDisks(n - 1 , buffer, d);
         // move one last element to the destination
         MoveTopTo(d);
         // put those n-1 back to the destination Tower!
         buffer.moveDisks(n-1, d,this);
         // Done
     }
 }
Ejemplo n.º 3
0
int main()
{
    MoveDisks(4, '1', '3', '2');
    return 0;
}