汉诺塔(非递归33个盘子)

// helloworld.cpp : Defines the entry point for the console application. //by陈墨仙2019-07-18 //完全不用递归解汉诺塔#include "stdafx.h" #include int h[34];//为了便于理解,0号元素不用,33个盘子int a[4][34]; int b[4]; int jihao; int dijici; void printH() { //system("cls"); for(int i = 1;i0;i--) { if(h[i]==3) { d=d+1; t = i; } } return d; } int jc1()//检测1号柱的盘子有几个{ int d = 0; int t = 34; for(int i = 33;i>0;i--) { if(h[i]==1) { d=d+1; t = i; } } return d; } void initH() { for(int i = 0;i0;i--) { if(h[i]==2) { d=d+1; t = i; } } return d; } int getTop(int zhuzi) { int d = 0; int t = 0; for(int i = 1;it) { t = i; } } return t; } bool jiou(int s) { if(s % 2 == 0) { return true; } else { return false; } } void change(int i,int yuan,int mubiao) { if(h[i] == yuan) { h[i] = mubiao; a[mubiao][b[mubiao]]=i; b[mubiao]=b[mubiao]+1; a[yuan][b[yuan]]=0; b[yuan]=b[yuan]-1; printf("h[%d]:%d->%d",i,yuan,mubiao); } else { printf("Error h[%d] = %d",i,h[i]); scanf("%d"); } jiancha(h); } int FastLog2(int x) { float fx; unsigned long ix, exp; fx = (float)x; ix = *(unsigned long*)&fx; exp = (ix >> 23) & 0xFF; return exp - 127; } int chu2(int n ,int cishu) { for(int j = 1; j
rar 文件大小:246.03KB