- 论坛徽章:
- 0
|
请问各位哪里有错呢?我在tc3下运行!!!
#include <stdio.h>;
#include <stdlib.h>;
#define OK 1;
#define OVERFLOW -2
#define NULL 0
typedef int SElemType;
typedef int Status;
typedef int Boolean;
#define TRUE 1
#define ERROR 0
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}Stack;
Status InitStack(Stack *s); //creat a null S
Status Push(Stack *s, SElemType e);
Status Pop(Stack *s,SElemType e);
Status stackEmpty(Stack *s);
Status InitStack(Stack *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;
}//InitStack
Status Push(Stack *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->;top++=e;
return OK;
}//Push
Status Pop(Stack *s,SElemType e)
{
if (s->;base==s->;top) return ERROR;
e=*--s->;top;
return e;
}//Pop
Boolean StackEmpty(Stack *s)
{
if (s->;top==s->;base) return TRUE;
else return ERROR;
}
Status DestroyStack(Stack *s)
/* The stack s has been destroyed. */
{
s->;top=NULL;
s->;stacksize=0;
free(s->;base);
s->;base=NULL;
return OK;
} /* DestroyStack */
main()
{ int n;
SElemType e;
Stack *s;
InitStack(s);
scanf("%d",&n);
while(n)
{
Push(s,n% ;
n=n/8;
}
while(!StackEmpty(s))
{ e=Pop(s,e);
printf("%d",e);
}
DestroyStack(s);
printf("\n" ;
}//Push是% 8 |
|