⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hannuo.cpp

📁 大学数据结构课程汉诺塔问题程序解决
💻 CPP
字号:
// hannuo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <memory.h>

typedef struct tagdish
{ 
	int num[100];
	int n;
}dish;

void move(int n,dish dismov,int a,int b,int c)
{
	dish newdis;
	static step=0;
	if(n==1)
	{
		if(c==1)
			printf("%6d",dismov.num[n-1]);
		if(c==2)
			printf("%12d",dismov.num[n-1]);
		if(c==3)
			printf("%18d",dismov.num[n-1]);
		step++;
		printf("%25d\n",step);
	}
	else
	{
		memcpy(&newdis.num,&dismov.num,sizeof(int)*(n-1));
		newdis.n=n-1;

		move(newdis.n,newdis,a,c,b);
		
		if(c==1)
			printf("%6d",dismov.num[n-1]);
		if(c==2)
			printf("%12d",dismov.num[n-1]);
		if(c==3)
			printf("%18d",dismov.num[n-1]);
		step++;
		printf("%25d\n",step);

		move(newdis.n,newdis,b,a,c);
		
	}
}
		

int main(int argc, char* argv[])
{
	dish alldish;
	int i;
	for(i=0;i<15;i++)
		alldish.num[i]=i+1;
	alldish.n=15;
    move(4,alldish,1,2,3);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -