没有合适的资源?快使用搜索试试~ 我知道了~
表达式求值的算法设计,很好的东西,比较容易实现的,希望大家能看看
资源推荐
资源详情
资源评论
#include "stdio.h"
#include "stdlib.h"
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack;
typedef struct{
float *base;
float *top;
int stacksize;
}SqStack1;
InitStack(SqStack &S){
S.base=(char*)malloc(STACK_INIT_SIZE*sizeof(char));
if(!S.base)
exit (OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
}
InitStack1(SqStack1 &S){
S.base=(float*)malloc(STACK_INIT_SIZE*sizeof(float));
if(!S.base)
#include "stdlib.h"
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack;
typedef struct{
float *base;
float *top;
int stacksize;
}SqStack1;
InitStack(SqStack &S){
S.base=(char*)malloc(STACK_INIT_SIZE*sizeof(char));
if(!S.base)
exit (OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
}
InitStack1(SqStack1 &S){
S.base=(float*)malloc(STACK_INIT_SIZE*sizeof(float));
if(!S.base)
exit (OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
}
Push(SqStack &S,char e){
if(S.top-S.base>=S.stacksize){
S.base=(char*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(char));
if(!S.base)
exit (OVERFLOW);
S.top=S.base+STACKINCREMENT;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
}
Pop(SqStack &S,char &e){
if(S.top==S.base)
return ERROR;
e=*--S.top;
}
GetTop(SqStack S){
char e;
if(S.top==S.base)
return ERROR;
e=*(S.top-1);
return e;
}
Push1(SqStack1 &S,float e){
if(S.top-S.base>=S.stacksize){
S.base=(float*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(float));
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
}
Push(SqStack &S,char e){
if(S.top-S.base>=S.stacksize){
S.base=(char*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(char));
if(!S.base)
exit (OVERFLOW);
S.top=S.base+STACKINCREMENT;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
}
Pop(SqStack &S,char &e){
if(S.top==S.base)
return ERROR;
e=*--S.top;
}
GetTop(SqStack S){
char e;
if(S.top==S.base)
return ERROR;
e=*(S.top-1);
return e;
}
Push1(SqStack1 &S,float e){
if(S.top-S.base>=S.stacksize){
S.base=(float*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(float));
剩余7页未读,继续阅读
资源评论
qinkeqing429
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功