#include <stdio.h> #include <string.h> struct list { int index; int a; char b; }; struct list s[100]; /*进堆比较*/ int comp1(char a,char b) { char op[4][2]={'*','/','+','-','(','(',')',')'}; int i; int a1,b1; for(i=0;i<4;i++) if (a==op[i][0] || a==op[i][1]) { a1=i; break; } for(i=0;i<4;i++) if (b==op[i][0] || b==op[i][1]) { b1=i; break; } if (a1<b1) return 1; else return 0; } int comp2(char a,char b) { char op[4][2]={'(','(','*','/','+','-',')',')'}; int i; int a1,b1; for(i=0;i<4;i++) if (a==op[i][0] || a==op[i][1]) { a1=i; break; } for(i=0;i<4;i++) if (b==op[i][0] || b==op[i][1]) { b1=i; break; } if (a1<b1) return 1; else return 0; } int oper(int a,int b,char op) { int result; if(op=='*') result=a*b; else if(op=='/') result=a/b; else if(op=='+') result=a+b; else if(op=='-') result=a-b; return result; }

评论