主题:[讨论]为什么啊
大家帮忙看下这个程序怎么不行啊,感觉没什么问题啊
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OK 1
#define EQUAL 1
#define OVERFLOW -1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef int Status ;
typedef char SElemType;
struct STACK
{
SElemType *base;
SElemType *top;
int stacksize;
};
typedef struct STACK SqStack;
typedef struct STACK *pSqstack;
Status InitStack(SqStack *S)
{
S->base=(SElemType *)malloc(STACK_INIT_SIZE *sizeof(SElemType));
if(!S->base)exit(OVERFLOW);
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
Status Push(SqStack S,SElemType e)
{
if(S.top - S.base>=S.stacksize)
{
S.base=(SElemType *) realloc(S.base,
(S.stacksize + STACKINCREMENT) * sizeof(SElemType));
if(!S.base)exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize += STACKINCREMENT;
}
*(S.top++)=e;
return OK;
}
Status Pop(SqStack S,SElemType *e)
{
if(S.top==S.base) return ERROR;
*e=*(--S.top);
return OK;
}
main()
{
int i;
char s[10];
char c;
SqStack S;
InitStack(&S);
for(i=0;s[i]=getchar()!='\n';i++)
for(i=0;s[i]!='\0';i++)
Push(S,s[i]);
printf("\nStack:");
while(S.top!=S.base)
{
Pop(S,&c);
printf("%c",c);
}
}
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OK 1
#define EQUAL 1
#define OVERFLOW -1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef int Status ;
typedef char SElemType;
struct STACK
{
SElemType *base;
SElemType *top;
int stacksize;
};
typedef struct STACK SqStack;
typedef struct STACK *pSqstack;
Status InitStack(SqStack *S)
{
S->base=(SElemType *)malloc(STACK_INIT_SIZE *sizeof(SElemType));
if(!S->base)exit(OVERFLOW);
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
Status Push(SqStack S,SElemType e)
{
if(S.top - S.base>=S.stacksize)
{
S.base=(SElemType *) realloc(S.base,
(S.stacksize + STACKINCREMENT) * sizeof(SElemType));
if(!S.base)exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize += STACKINCREMENT;
}
*(S.top++)=e;
return OK;
}
Status Pop(SqStack S,SElemType *e)
{
if(S.top==S.base) return ERROR;
*e=*(--S.top);
return OK;
}
main()
{
int i;
char s[10];
char c;
SqStack S;
InitStack(&S);
for(i=0;s[i]=getchar()!='\n';i++)
for(i=0;s[i]!='\0';i++)
Push(S,s[i]);
printf("\nStack:");
while(S.top!=S.base)
{
Pop(S,&c);
printf("%c",c);
}
}