如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>#definemax100#defineElemtypefloattypedefstruct{char*data;inttop;intstacksize;}seqstack;typedefstruct{Elemtype*data1;inttop;intstacksize;}seqstack1;intprior(charstr1,charstr2);//字符栈intinitstack(seqstack&L){L.data=(char*)malloc(max*sizeof(char));if(L.data==NULL){printf("内存分配失败!\n");exit(0);}L.top=-1;L.stacksize=max;return1;}intpushstack(seqstack&L,charch){if(L.top==L.stacksize-1){printf("栈满!\n");return0;}L.top++;L.data[L.top]=ch;return1;}charpopstack(seqstack&L){if(L.top==-1)printf("空栈!\n");elsereturnL.data[L.top--];}chargettop(seqstackL){if(L.top==-1)printf("空栈!\n");elsereturnL.data[L.top];}//求值栈intinitstack1(seqstack1&L1){L1.data1=(Elemtype*)malloc(max*sizeof(Elemtype));if(L1.data1==NULL){printf("内存分配失败!\n");exit(0);}L1.top=-1;L1.stacksize=max;return1;}intpushstack1(seqstack1&L1,Elemtypex){if(L1.top==L1.stacksize-1){printf("栈满!\n");return0;}L1.top++;L1.data1[L1.top]=x;return1;}floatpopstack1(seqstack1&L1){floatn;if(L1.top==-1)printf("空栈!\n");elsen=L1.data1[L1.top--];returnn;}//优先级比较intprior(charstr1,charstr2){switch(str1){case'(':case'#':return0;case'+':case'-':switch(str2){case'#':case'+':case'-':return1;case'*':case'/':return0;}break;case'*':case'/':return1;}}//计算floatcalculate(floata,floatb,charch){if(ch=='*')return(a*b);elseif(ch=='/')return(a/b);elseif(ch=='+')return(a+b);elsereturn(a-b);}//字符转换为实数floattransform(char*ch){inti=0,k=0,j;floatn,n2=0,n1=0;charstr[10];while(ch[i]>='0'&&ch[i]<='9')//先转整数部分{n1=n1*10+ch[i]-'0';i++;}j=i;if(ch[j]==0)//如果只有整数部分,返回1returnn1;else{while(ch[j])//将小数部分放到一个数组{str[k]=ch[j];k++;j++;}str[k]='\0';k--;//跳过'\0'while(str[k]!='.')//转小数部分{n2=n2*0.1+str[k]-'0';k--;}n2=n2*0.1;n=n1+n2;returnn;}}