动态演示汉诺塔算法的实现过程

来源:百度知道 编辑:UC知道 时间:2024/04/30 03:21:10
只可使用:顺序结构、选择结构、循环结构、数组、函数、指针
使用c语言编程

// YUNA_2006_7_10
// The way to deal with hannio without digui
#include <iostream>
using namespace std;
#include <malloc.h>

// I will use a stuct to settle the problem
// the struct below is one point of the stuct
struct step
{
int counter; // the number of the disk
int begin; // the begin number
int temper; // the temp number
int end; // the end number
struct step *pre; // the pointer to point before
};

struct step *root = ( step * )malloc( sizeof( step ) ); // this is the end of the stuct

// fucion main begin here
int main()
{
step *temp = ( step * )malloc( sizeof( step ) ); // the temp to put data for temp
step *newstep; // the new step
step *top = root; // top is root in the first
cout << "Input the number of the disc:" << endl; // prompt
cin >> root->count