C语言表达式计算器
为了方便了解流程,在程序中把计算过程也输出了.而且栈操作的实现部分也是自己实现的.程序用两个栈,optr寄存运算符,opnd寄存操作数和运算结果.输入的表达式以等号结束,例如:2*(1+2)=
/**************表达式计算器************/0Q7\"s5k#J
#include <stdio.h>2k2y+o4Wv1V,@
#include <stdlib.h>HLIZ8C
#include <string.h>4I `q5q E mw
#include <conio.h>6]eP:GN#daaA6s
#include <malloc.h>"o1ZlLl5Tm'Qy
#define STACK_SIZE 100
#define APPEND_SIZE 10r+Pt M5T3cf z`
VpKo2u8R0tN(O
struct SNode{
float data; /*存放操作数或者计算结果*/
char ch; /*存放运算符*/Q6z&CS-BB5~vZ
};"a-W2lb3E|G:M
BW ho/n{!Y+U z
struct Stack{
SNode *top;"n(a Y9oOD}B
SNode *base;|9y]hH5Z1['c5qa&X
int size;
};
/*栈操作函数*/|k[%] F ^S.fn
int InitStack(Stack &S); /*创建栈*/
int DestroyStack(Stack &S); /*销毁栈*/
int ClearStack(Stack &S); /*清空栈*/
int GetTop(Stack S, SNode &e); /*取出栈顶结点并返回节点值*/
int Push(Stack &S,SNode e); /*将结点e压入栈*/
int Pop(Stack &S,SNode &e); /*删除栈顶结点并返回其节点值*/