1 / 5
文档名称:

汉诺塔非递归算法C语言实现.doc

格式:doc   大小:15KB   页数:5页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

汉诺塔非递归算法C语言实现.doc

上传人:wz_198614 2017/11/8 文件大小:15 KB

下载得到文件列表

汉诺塔非递归算法C语言实现.doc

文档介绍

文档介绍:汉诺塔非递归算法C语言实现
#include<>
#include<>
#define CSZL 10
#define FPZL 10
typedef struct hanoi
{
int n;
char x,y,z;
}hanoi;
typedef struct Stack
{
hanoi *base,*top;
int stacksize;
}Stack;
int InitStack(Stack *S)
{
S->base=(hanoi *)malloc(CSZL*sizeof(hanoi));
if(!S->base)
return 0;
S->top=S->base;
S->stacksize=CSZL;
return 1;
}
int PushStack(Stack *S,int n,char x,char y,char z)
{
if(S->top-S->base==S->stacksize)
{
S->base=(hanoi *)realloc(S->base,(S->stacksize+FPZL)*sizeof(hanoi)); if(!S->base)
return 0;
S->top=S->base+S->stacksize;
S->stacksize+=FPZL;
}
S->top->n=n;
S->top->x=x;
S->top->y=y;
S->top->z=z;
S->top++;
return 1;
}
int PopStack(Stack *S,int *n,char *x,char *y,char *z)
{
if(S->top==S->base)
return 0;
else
{
S->top--;
*n=S->top->n;
*x=S->top->x;
*y=S->top->y;
*z=S->top->z;
return 1;
}
}
int EmptyStack(Stack *S)
{
if(S->base==S->top)
return 1;
else
return 0;
}
int i=1;
void Move(char x,char z)
{
printf("\n\n\t\t第%d部,从%c移到%c。",i++,x,z);
}
int main()
{
int n;
char x,y,z;