#include "stdio.h" #include "stdlib.h" #include "string.h" struct node{ int arr; struct node *next; }; typedef struct node Node; typedef Node *Stack; struct stacktop{ Stack top; }; typedef struct stacktop *Top; int jisuan(int sr1,int sr2,int sr3); int opinion4(char *ptr,int *num); int opinion3(char ch); int opinion2(char ch); int opinion(char ch); void StackPush(int ch,Top ptop); void StackPop(int *pi,Top ptop); int main(void) {
int value1; int value2; int value3; char ch[100]; int R,a; int i=0; Top svalue; Top sctype; svalue=(Top)malloc(sizeof(struct stacktop)); svalue->top=NULL; sctype=(Top)malloc(sizeof(struct stacktop)); sctype->top=NULL; StackPush('a',sctype); printf("请输入一个表达式:\n-->"); gets(ch); while(ch!=NULL&&ch[i]!='\0') { if(opinion(ch[i])==1)//如果是操作符 { if(opinion2(ch[i])<=opinion2(sctype->top->arr)) { StackPop(&value1,svalue); StackPop(&value2,svalue); StackPop(&value3,sctype);
int jisuan(int sr1,int sr2,int sr3) { switch((char)sr3) { case '+':return sr2+sr1; case '-':return sr2-sr1; case '*':return sr2*sr1; case '/':return sr2/sr1; } }
/*将字符转换成数字*/ int opinion4(char *ptr,int *num) { int x; int b=*num; int c=0; int d,e,f; int brr[50]; int fang=1; int total=0; x=strlen(ptr); while((opinion3(ptr[b])==1)&&b<x) { brr[c]=ptr[b]-48; b++; c++; }