大侠们看一下这个程序哪里错了?
typedef struct{
short int retAddr;/*标记返回时的位置*/
int nParam; /*参数n*/
char fromParam;/*参数frompeg*/
char auxParam;/*参数auxpeg*/
char toParam;/*参数topeg*/
}Datatype;
#include<stdio.h>
#include"SeqStack.h"
#define MaxNum 20
void Simtowers(int n,char fromPeg,char auxPeg,char toPeg,SeqStack curr)
{
DataType curr;/*当前工作区数据元素*/
SeqStack s;/*模拟系统运行时栈的堆栈*/
char temp;
short int i;
SSInitiate(&s);/**初始化堆栈S/
/*当前工作区初始化、模仿主函数的第一次调用*/
curr.retAddr=1;
curr.nParam=n;
curr.fromParam=fromPeg;
curr.fromauxParam=auxPeg;
curr.fromttoParam=toPeg;
SSPush(&s,curr);/*当前工作区入栈*/
/*以下为模拟递归出口*/
start:
if(curr.nParam==1)
{
printf("\n%s%c%s%c","Move Disk 1 from Peg",curr.fromParam,"toPeg",curr.toParam);
i=curr.retAddr;
SSPop(&s,&curr);/*出栈得到新的当前工作区数据元素*/
switch(i)
{
case 1: goto lable1;
case 2: goto lable2;
case 3: goto lable3;
}
}
/*以下模拟递归自调用过程*/
SSPush(&s,curr);/*当前工作区数据元素入栈*/
curr.nParam--;
temp=curr.auxParam;
curr.auxParam=curr.toParam;
curr.toParam=temp;
curr.retAddr=2;
goto start;
/*以下模拟返回第一次递归调用*/
lable2:
printf("\n%s%d%s%c%s%c","Move Disk",curr.nParam,"from Peg",curr.fromParam,"toPeg",curr.toParam);
SSPush(&s,curr);/*当前工作区数据元素入栈*/
curr.nParam--;
temp=curr.fromParam;
curr.fromParam=curr.auxParam;
curr.auxParam=temp;
curr.retAddr=3;
goto start;
/*以下模拟返回第2次递归调用*/
lable3:
i=curr.retAddr;
SSPop(&s,&curr);/*出栈得到新的当前工作区数据元素*/
switch(i)
{
case 1: goto lable1;
case 2: goto lable2;
case 3: goto lable3;
}
/*以下模拟返回主函数*/
lable1:
return;
}
/*下面是调用的函数*/
#include<stdio.h>
#define MaxSize 100
typedef int DataType;
typedef struct
{
DataType list[MaxSize];
int top;
}SeqStack;
void SSInitiate(SeqStack *s)
{
s->top=0;
}
int SSPush(SeqStack *s,DataType x)
{
if(s->top>=MaxSize)
{
printf("队栈已满!\n");
return 0;
}
else
{
s->list[s->top]=x;
s->top++;
return 1;
}
}
int SSPop(SeqStack *s,DataType *d)
{
if(s->top<=0)
{
printf("队栈已空无法出栈!\n");
return 0;
}
else
{
s->top--;
*d=s->list[s->top];
return 1;
}
}
int SSGetTop(SeqStack s,DataType *d)
{
if(s.top<=0)
{
printf("队栈已空无法出栈!\n");
return 0;
}
else
{
*d=s.list[s.top-1];
return 1;
}
}