数据结构和算法 各位大神求教一下我写的程序错在哪儿了?
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
#define STACK_INIT_SIZE 100
#define DFGHF_DXFGG_DFG 10
typedef int ElemType;
typedef struct
{
ElemType *base;
ElemType *top;
int StackSize;
}sqStack;
void InitStack(sqStack *s)
{
s->base=(ElemType *)malloc(STACK_INIT_SIZE * sizeof(ElemType));
if(!s->base){
exit(0);
}
s->top=s->base;
s->StackSize=STACK_INIT_SIZE;
}
void pushStack(sqStack *s,ElemType e)
{
if(s->top-s->base>=s->StackSize);
{
s->base=(ElemType *)realloc(s->base,(s->StackSize+DFGHF_DXFGG_DFG) * sizeof(ElemType));
if(!s->base)
{
exit(0);
}
s->top=s->base+s->StackSize;
s->StackSize=s->StackSize+DFGHF_DXFGG_DFG;
}
*(s->top)=e;
s->top++;
}
void Pop(sqStack *s,ElemType *e)
{
if(s->top==s->base)
{
return;
}
*e=*--(s->top);
}
int StackLen(sqStack s)
{
return(s.top-s.base);
}
main()
{
sqStack s;
ElemType c;
ElemType *g;
int Len,i;
InitStack(&s);
Len=StackLen(s);
printf("此时站的容量是:%d\n",s.StackSize);
printf("此时站的元素个数是:%d\n",Len);
printf("请输入进站元素:");
for(i=0;i<10;i++)
{
scanf("%d\n",&c);
pushStack(&s,c);
}
Len=StackLen(s);
printf("此时站的容量是:%d\n",s.StackSize);
printf("此时站的元素个数是:%d\n",Len);
for(i=0;i<Len;i++)
{
Pop(&s,&c);
}
printf("此时站的容量是:%d\n",s.StackSize);
printf("此时站的元素个数是:%d\n",Len);
} 出错在哪?写一下错误。 没错了,谢谢!:smile 感谢分享 得活很久很久才可以做得到。 看不懂
页:
[1]