C语言表达式计算器
为了方便了解流程,在程序中把计算过程也输出了.而且栈操作的实现部分也是自己实现的.^%P7clKy/x程序用两个栈,optr寄存运算符,opnd寄存操作数和运算结果.输入的表达式以等号结束,例如:2*(1+2)=+Gp Fp2K Y
/**************表达式计算器************/
#include <stdio.h>
#include <stdlib.h>U9N!b'M j@&{oxA{1c
#include <string.h>
#include <conio.h>
#include <malloc.h>#@)\ru@
,s`Tq5p3geL j
#define STACK_SIZE 100@(nd8C tXjO[[ s \
#define APPEND_SIZE 10
nbkf;q#^.bG'J
struct SNode{|%Gqy7G5N
float data; /*存放操作数或者计算结果*/
char ch; /*存放运算符*/2| j:Qek|(T6uM%q
};
struct Stack{iZ]hr6U(LBc&k[n
SNode *top;W*Ts(t}nS
SNode *base;
int size;
};kY:_kL
LO l ERg
/*栈操作函数*/ZO BVr Wh1?P ^.I
int InitStack(Stack &S); /*创建栈*/9]A%_1c P1F
int DestroyStack(Stack &S); /*销毁栈*/ KVne3ZKb#H
int ClearStack(Stack &S); /*清空栈*/;P-t1I8P'R$G!jg.Mv
int GetTop(Stack S, SNode &e); /*取出栈顶结点并返回节点值*/6X F:aD$F3ohB
int Push(Stack &S,SNode e); /*将结点e压入栈*/