欢迎来到天天文库
浏览记录
ID:61479511
大小:21.50 KB
页数:6页
时间:2021-02-03
《用C语言写的计算器源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、用C语言写的计算器源代码.txt什么叫神话?请听男人向你表达爱意;什么叫传说?请听男人对你的承诺;什么叫梦境?请看你自己听到前两者时的反应。用C语言写的计算器源代码#include#include#include#include#includetypedeffloatDataType;typedefstruct{DataType*data;intmax;inttop;}Stack;voidSetStack(Stack*S,intn){S->data=(DataType*)ma
2、lloc(n*sizeof(DataType));if(S->data==NULL){printf("overflow");exit(1);}S->max=n;S->top=-1;}voidFreeStack(Stack*S){free(S->data);}intStackEmpty(Stack*S){if(S->top==-1)return(1);return(0);}DataTypePeek(Stack*S){if(S->top==S->max-1){printf("Stackisempty!");exit(1);}return(S->data[S->top]);}
3、voidPush(Stack*S,DataTypeitem){if(S->top==S->max-1){printf("Stackisfull!");exit(1);}S->top++;S->data[S->top]=item;}DataTypePop(Stack*S){if(S->top==-1){printf("Popanemptystack!");exit(1);}S->top--;return(S->data[S->top+1]);}typedefstruct{charop;intinputprecedence;intstackprecedence;}Dat
4、aType1;typedefstruct{DataType1*data;intmax;inttop;}Stack1;voidSetStack1(Stack1*S,intn){S->data=(DataType1*)malloc(n*sizeof(DataType1));if(S->data==NULL){printf("overflow");exit(1);}S->max=n;S->top=-1;}voidFreeStack1(Stack1*S){free(S->data);}intStackEmpty1(Stack1*S){if(S->top==-1)return(1);
5、return(0);}DataType1Peek1(Stack1*S){if(S->top==S->max-1){printf("Stack1isempty!");exit(1);}return(S->data[S->top]);}voidPush1(Stack1*S,DataType1item){if(S->top==S->max-1){printf("Stackisfull!");exit(1);}S->top++;S->data[S->top]=item;}DataType1Pop1(Stack1*S){if(S->top==-1){printf("Popan
6、emptystack!");exit(1);}S->top--;return(S->data[S->top+1]);}DataType1MathOptr(charch){DataType1optr;optr.op=ch;switch(optr.op){case'+':case'-':optr.inputprecedence=1;optr.stackprecedence=1;break;case'*':case'/':optr.inputprecedence=2;optr.stackprecedence=2;break;case'(':optr.inputpreceden
7、ce=3;optr.stackprecedence=-1;break;case')':optr.inputprecedence=0;optr.stackprecedence=0;break;}return(optr);}voidEvaluate(Stack*OpndStack,DataType1optr){DataTypeopnd1,opnd2;opnd1=Pop(OpndStack);opnd2=Pop(OpndStack);switch(optr.op){case'+':Push(OpndStack,opnd2
此文档下载收益归作者所有