C语言表达式计算器
为了方便了解流程,在程序中把计算过程也输出了.而且栈操作的实现部分也是自己实现的.程序用两个栈,optr寄存运算符,opnd寄存操作数和运算结果.输入的表达式以等号结束,例如:2*(1+2)=` yP+Z"|b*h2F
/**************表达式计算器************/$Y$Q+xnj:WN/j2^
#include <stdio.h>1f/qUq}f&I2Hm
#include <stdlib.h>O5aZ"^ _GM
#include <string.h>'@Kd-nC {
#include <conio.h>
#include <malloc.h>6I8X M)_S6q8h
9~8~0t6^ i
#define STACK_SIZE 100pGQ*Ft5D.H\#b
#define APPEND_SIZE 10
*FHj(e to)Q2S^c
struct SNode{8?vN*p8x]2L DjB/_j
float data; /*存放操作数或者计算结果*/Sq/K9[GF^z
char ch; /*存放运算符*/;wII-n(h+^
};
struct Stack{
SNode *top;
SNode *base;
int size;
};
v2z8ILT4mS&O5`'v'w
/*栈操作函数*/?x;~2[ i ru
int InitStack(Stack &S); /*创建栈*/Z0nC'ba
int DestroyStack(Stack &S); /*销毁栈*/
int ClearStack(Stack &S); /*清空栈*/
int GetTop(Stack S, SNode &e); /*取出栈顶结点并返回节点值*/M$RT!NS
int Push(Stack &S,SNode e); /*将结点e压入栈*/
int Pop(Stack &S,SNode &e); /*删除栈顶结点并返回其节点值*/