#include#include#definemaxsize100typedefdoubledatatype1;typedefchardatatype2;typedef">
c語(yǔ)言計(jì)算器源代碼.doc

c語(yǔ)言計(jì)算器源代碼.doc

ID:51934290

大?。?7.00 KB

頁(yè)數(shù):7頁(yè)

時(shí)間:2020-03-19

c語(yǔ)言計(jì)算器源代碼.doc_第1頁(yè)
c語(yǔ)言計(jì)算器源代碼.doc_第2頁(yè)
c語(yǔ)言計(jì)算器源代碼.doc_第3頁(yè)
c語(yǔ)言計(jì)算器源代碼.doc_第4頁(yè)
c語(yǔ)言計(jì)算器源代碼.doc_第5頁(yè)
資源描述:

《c語(yǔ)言計(jì)算器源代碼.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。

1、#include#include#include#definemaxsize100typedefdoubledatatype1;typedefchardatatype2;typedefstructstack1{datatype1data1[maxsize];inttop1;/*棧頂元素*/}seqstack1,*pseqstack1;/*順序棧*/typedefstructstack2{datatype2data2[maxsize];inttop2;/*棧頂元素*/}seqstack2,*pseq

2、stack2;/*順序棧*//*棧的初始化*/pseqstack1init_seqstack1(void){pseqstack1S;S=(pseqstack1)malloc(sizeof(pseqstack1));if(S)S->top1=-1;returnS;}pseqstack2init_seqstack2(void){pseqstack2S;S=(pseqstack2)malloc(sizeof(pseqstack2));if(S)S->top2=-1;returnS;}/*判斷???/intempty_seqstack1(pseqstack1S

3、){if(S->top1==-1)return1;elsereturn0;}intempty_seqstack2(pseqstack2S){if(S->top2==-1)return1;elsereturn0;}/*X入棧*/intpush_seqstack1(pseqstack1S,datatype1X){if(S->top1==maxsize-1){printf("棧滿,無(wú)法入棧!");return0;}else{S->top1++;S->data1[S->top1]=X;return1;}}intpush_seqstack2(pseqstac

4、k2S,datatype2X){if(S->top2==maxsize-1){printf("棧滿,無(wú)法入棧!");return0;}else{S->top2++;S->data2[S->top2]=X;return1;}}/*X出棧*/intpop_seqstack1(pseqstack1S,datatype1*X){if(empty_seqstack1(S))return0;else{*X=S->data1[S->top1];S->top1--;return1;}}intpop_seqstack2(pseqstack2S,datatype2*X

5、){if(empty_seqstack2(S))return0;else{*X=S->data2[S->top2];S->top2--;return1;}}/*求棧頂元素*/intgettop_seqstack1(pseqstack1S,datatype1*X){if(empty_seqstack1(S))return0;else*X=S->data1[S->top1];return1;}intgettop_seqstack2(pseqstack2S,datatype2*X){if(empty_seqstack2(S))return0;else*X=S

6、->data2[S->top2];return1;}/*判斷字符是否為操作數(shù)。若是返回1,否則返回0*/intisnum(charc){if(c>='0'&&c<='9')return1;elsereturn0;}/*求后綴表達(dá)式的值*/doublepostfix_exp(char*A){pseqstack1S;/*定義棧S*/doubleoperand=0;doubleresult;/*存放棧頂元素*/doublea;/*運(yùn)算符ch前的操作數(shù)出棧存入a*/doubleb;/*運(yùn)算符ch后的操作數(shù)出棧存入b*/doublec;/*c==achb*/ch

7、arch;/*存放讀取到的表達(dá)式(A)的字符*/ch=*A++;/*讀表達(dá)式字符=>A*/S=init_seqstack1();/*初始化棧*/while(ch!='#')/*遇到元素!='#'時(shí)*/{if(isnum(ch))/*判斷ch是否為數(shù)字字符,計(jì)算出操作數(shù)*/operand=operand*10+(ch-'0');else/*否則*/{if(operand){push_seqstack1(S,operand);/*當(dāng)前字符不是數(shù)字,操作數(shù)結(jié)束,要入棧*/operand=0;}if(ch!='@'&&ch!=''){pop_seqstack1

8、(S,&b);/*運(yùn)算符ch后的操作數(shù)出棧存入b*/pop_seqstack1(S,&a);/

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動(dòng)畫(huà)的文件,查看預(yù)覽時(shí)可能會(huì)顯示錯(cuò)亂或異常,文件下載后無(wú)此問(wèn)題,請(qǐng)放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫(kù)負(fù)責(zé)整理代發(fā)布。如果您對(duì)本文檔版權(quán)有爭(zhēng)議請(qǐng)及時(shí)聯(lián)系客服。
3. 下載前請(qǐng)仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時(shí)可能由于網(wǎng)絡(luò)波動(dòng)等原因無(wú)法下載或下載錯(cuò)誤,付費(fèi)完成后未能成功下載的用戶請(qǐng)聯(lián)系客服處理。