关于数据结构栈 请高手看看 我这程序什么地方错了!我是菜鸟 谢谢了

来源:百度知道 编辑:UC知道 时间:2024/09/24 10:14:42
#define MAXSIZE 100
#include <stdio.h>
typedef stuct{
DateType data[MAXSIZE];
int top;
} SeqStack,*PSeqStack;

PSeqStack Init_SeqStack(void)
{
PSeqStack S;
S=(PSeqStack)malloc(sizeof(SeqStack));
if(S)
S->top=-1;
return S;
}
int Empty_SeqStack(PSeqStack S)
{
if(S->top==-1)
return 1;
else
return 0;
}
int Push_SeqStack(PSeqStack S,DataType x)
{
if(S->top==MAXSIZE-1)
return 0;
else
{
S->top++;
S-data[S->top]=x;
return 1;
}
}
int Pop_Seqstack(PSeqStack S,DataType *x)
{
if(Empty_SeqStack(S))
return 0;
else
{
*x=S->data[S->top];
S->top--;
return 1;
}
}
int GetTop_SeqStack(PSeqStack S,DataType *X)
{
if(Empty_SeqStack(S))
return 0;
else
*x=S->data[S->top];
return (1)

一、数据类型 DateType没有定义啊!!应该在程序最上面加一条:
#define DateType int

二、另外main函数里面也有错误,x的定义与使用有问题; Destory_SeqStack(PSeqStack *S)函数也有错误。这两个函数应改成:
void Destory_SeqStack(PSeqStack S) /*把S前的星号去掉*/
{
if(S)
free (S);
S=NULL;
return ;/*把星号统统去掉*/
}
void mian()
{
int *x;
PSeqStack S;
S=Init_SeqStack();
/*Empty_SeqStack(S);这句没有用,去掉*/
Push_SeqStack(S,15);
if(GetTop_SeqStack(S,x))/*返回值不能给x,那样就全乱套了,应该用if验证返回值*/
printf("%d",*x); /*这里要加个星号,因为x是个整数指针*/
Destory_SeqStack(S);
}

你再调试一下试试,有错误再告诉我,我是计算机硕士生,呵呵