|
这个程序自己写的有些局限,可惜只能对0~9的四则运算起作用,我正在对它进行改进,希望各位能提出好的意见,谢谢!! #include<stdio.h> #include<math.h> #include<stdlib.h> #include<ctype.h> #define maxism 15 typedef struct stack { char stack[maxism]; int top; }stack; stack *L; char after[maxism]; void initialstack(stack *T)
void push(stack *T,int x)
void change() { int i=0,j,m=0; char str[maxism],ch; printf("please enter the compute expression(only contained +,-,*,/,(,),begin and end with '#'): "); gets(str); i++; ch=str[i]; initialstack(L); while(ch!='#') { switch(ch) { case'(': L->top++; L->stack[L->top]=ch; break; case')': while(L->stack[L->top]!='(') { after[m]=L->stack[L->top]; L->top--; m++; } L->top--; break; case'+': case'-': while(L->top!=0&&L->stack[L->top]!='(') { after[m]=L->stack[L->top]; L->top--; m++; } L->top++; L->stack[L->top]=ch;
上一篇:简单图形模拟吃豆游戏
下一篇:进程调度模拟程序
|