栈的基本操作
问题是:S.base=(ElemType*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(ElemType))非法的间接寻址 ;语法错误 : “)”求大神帮忙看一下,感激不尽~
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include<iostream>
using namespace std;
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
#define TRUE 1;
#define FALSE 0;
#define OVERFLOW -1
#define OK 1
#define ERROR -2
typedef char ElemType;
typedef int Status;
typedef struct Node{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S)
{
S.base=(ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}
Status GetTop(SqStack &S,ElemType &e){
if (S.top==S.base)
return ERROR;
e=*(S.top-1);
return OK;
}
bool StackEmpty(SqStack S){
if(S.top==S.base)
return TRUE;
return FALSE;
}
Status Push(SqStack &S,ElemType e){
ElemType* newbase;
if(S.top-S.base>=S.stacksize){
S.base=(ElemType*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(ElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*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 Num) { // 算法3.1
// 对于输入的任意一个非负十进制整数,打印输出与其等值的八进制数
ElemType e;
SqStack S;
InitStack(S); // 构造空栈
while (Num) {
Push(S, Num % 8);
Num = Num/8;
}
while (!StackEmpty(S)) {
Pop(S,e);
printf ("%d", e);
}
printf("\n");
} // conversion