主题:[讨论]栈??
各位高手,帮忙更正一下,谢谢
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1
#define STACKINTTSIZE 100
#define STACKINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
Status StackEmpty(SqStack S)
{
if(S.top==S.base)
return OK;
else exit(ERROR);
Status InitStack(SqStack *S)
{
S->base=(ElemType *)malloc(STACKINTTSIZE *sizeof(ElemType));
if(!S->base) exit(ERROR);
S->top=S->base;
S->stacksize=STACKINTTSIZE;
return OK;
}
Status Push(SqStack *S,ElemType e)
{
if(S->top-S->base>=S->stacksize)
{
S->base=(ElemType *)realloc(S->base,(S->stacksize+STACKINTTSIZE) *sizeof(ElemType));
if(!S->base) exit(ERROR);
S->top=S->base+S->stacksize;
S->stacksize+=STACKINTTSIZE;
}
*S->top++=e;
return OK;
}
Status Pop(SqStack *S,ElemType *e)
{
if(S->top==S->base) return ERROR;
*e=*--S->top;
return OK;
}
void conversion()
{
int N;
Stack S;
IniStack(&S);
scanf("%d",N);
while(N)
{
Push(&S,N%8);
N=N/8;
}
while(!StackEmpty(S))
{
Pop(&S,N);
printf("%d",e);
}
}
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1
#define STACKINTTSIZE 100
#define STACKINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
Status StackEmpty(SqStack S)
{
if(S.top==S.base)
return OK;
else exit(ERROR);
Status InitStack(SqStack *S)
{
S->base=(ElemType *)malloc(STACKINTTSIZE *sizeof(ElemType));
if(!S->base) exit(ERROR);
S->top=S->base;
S->stacksize=STACKINTTSIZE;
return OK;
}
Status Push(SqStack *S,ElemType e)
{
if(S->top-S->base>=S->stacksize)
{
S->base=(ElemType *)realloc(S->base,(S->stacksize+STACKINTTSIZE) *sizeof(ElemType));
if(!S->base) exit(ERROR);
S->top=S->base+S->stacksize;
S->stacksize+=STACKINTTSIZE;
}
*S->top++=e;
return OK;
}
Status Pop(SqStack *S,ElemType *e)
{
if(S->top==S->base) return ERROR;
*e=*--S->top;
return OK;
}
void conversion()
{
int N;
Stack S;
IniStack(&S);
scanf("%d",N);
while(N)
{
Push(&S,N%8);
N=N/8;
}
while(!StackEmpty(S))
{
Pop(&S,N);
printf("%d",e);
}
}