博前感想:
表示式求值比較難理解,特別是各種表示式的優先順序需要自己設計,還要看自己怎麼把這個優先順序的比較關係帶入到程式裡面。這裡我門可以自己寫乙個簡單的棧,也可以呼叫系統自帶的#include。
**塊:
#include #include #include #include //stack有top(獲取站頂),push(進入站),pop函式(出戰)
using namespace std;
stack optr; //運算控制符
stack optn; //數字站
int zuobiao(char ch) //獲取座標給上面的函式來選擇優先順序
return biao;
}char quyou(char ch2,char ch1) //運算子間的優先順序關係
, ,
, ,
, ,
, };
int biao1,biao2;
biao1=zuobiao(ch1);
biao2=zuobiao(ch2);
return youxian[biao1][biao2];
}int cal(int a,char c,int b)
return 0;
}int jisuan()
else //說明是個位數
h=getchar(); //再次讀入
} else //輸入h的不是數字的情況
}} return optn.top(); //top的括號不能忘了
//cout<>n;
cout<<"請輸入"《這個實驗主要是為了加深對棧的理解。
(複習)資料結構 棧 表示式求值
很久都沒有寫棧的程式了呢 由腦補可以字尾式求值是要用到棧的。所有說表示式求值可以分為兩部分 1.把中綴式轉換為字尾式 2.字尾式求值 include include include include include include include using namespace std char s ...
資料結構 棧實現表示式求值
expression.h calc expression 功能 利用棧實現整數表示式求值 輸入 表示式字串 輸出 求值結果 日期 2018 04 05 ifndef expression h define expression h include include include include 將中...
資料結構 表示式求值
一 實驗目的 通過乙個具體實際應用例子,加深對資料結構課程的理解,能夠綜合利用資料結構以及c語言的知識設計程式,應用到實際問題中去。二 實驗題目 常見的小型計算器可以通過輸入乙個由運算元和操作符組成的表示式計算出結構,設計乙個程式模擬上述功能。本實驗要求至少建立兩個棧和乙個運算子優先順序比較表,按照...