当前位置: 代码迷 >> C语言 >> [转载]Tower of Hanoi
  详细解决方案

[转载]Tower of Hanoi

热度:393   发布时间:2006-07-06 11:59:06.0
[转载]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);}

搜索更多相关的解决方案: Hanoi  Tower  

----------------解决方案--------------------------------------------------------
  相关解决方案