[转载]Tower of Hanoi
hey guys .. this is an amazing code to solve the tower of Hanoi problem .. done without any recurtion and stack use .. check this out ..
// just copy paste this into a .c file and // use gcc to compile .. ( for linux .. )
main(
){int
z,y,n
;scanf("%d",&n);
for(y=1;(1<<n)-y
;y<<=z-1,printf(
"disk %i from %i to %i.\n"/**/
,z,(y&y-1)%3,((y|y-1)+1)%3),y
++)for(z=1;!(y&1);z++,y>>=1);}
----------------解决方案--------------------------------------------------------