简单的C语言数据结构编程问题~~~~
来源:百度知道 编辑:UC知道 时间:2024/06/17 14:56:26
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define TRUE 1
#define FALSE 0
typedef int Status;
typedef struct
{
int ord;
int di;
}SElemType ;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
SqStack S;
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 GetTop(SqStack S, SElemType &e)
{
if(S.top==S.base)
return ERROR;
e = *(S.top - 1);
return OK;
}
Status Push(SqStack &S, SElemType e)
{
if(S.top - S.base >= S.stacks
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define TRUE 1
#define FALSE 0
typedef int Status;
typedef struct
{
int ord;
int di;
}SElemType ;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
SqStack S;
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 GetTop(SqStack S, SElemType &e)
{
if(S.top==S.base)
return ERROR;
e = *(S.top - 1);
return OK;
}
Status Push(SqStack &S, SElemType e)
{
if(S.top - S.base >= S.stacks
只需将所有的&去掉即可,程序已经改好,如下:
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define TRUE 1
#define FALSE 0
typedef int Status;
typedef struct
{
int ord;
int di;
}SElemType ;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
SqStack S;
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 GetTop(SqStack S, SElemType e)
{
if(S.top==S.base)
return ERROR;
e = *(S.top - 1);
return OK;
}
Status Push(SqStack S, SElemType e)
{
if(S.top - S.base >= S.stac