本文介绍了如何在C语言编程环境中利用栈数据结构来实现表达式的计算过程,包括逆波兰表示法的应用和算术运算符的操作。
#include
#include
#define stack_init_size 100
#define stackincreament 10
typedef struct {
char *base;
char *top;
int stacksize;
} Sqstackcha;
typedef struct {
double *base;
double *top;
int stacksize;
} Sqstackdou;
Sqstackcha optr;
Sqstackdou opnd;
char gettop(Sqstackcha &s);
double gettop(Sqstackdou &s);
int precede(Sqstackcha &s, char c);
void initstack(Sqstackcha &s) {
// 初始化操作符栈
}
void initstack(Sqstackdou &s) {
// 初始化操作数栈
}
double opterate(double a, char theta, double b);
void push(Sqstackcha &s, char e);
void push(Sqstackdou &s, double e);
char pop(Sqstackcha &s, char e);
double pop(Sqstackdou &s, double e);