(複習)資料結構 棧 表示式求值

2021-07-22 06:22:41 字數 1092 閱讀 1001

很久都沒有寫棧的程式了呢……

由腦補可以字尾式求值是要用到棧的。

所有說表示式求值可以分為兩部分:

——1.把中綴式轉換為字尾式

——2.字尾式求值

#include

#include

#include

#include

#include

#include

#include

using namespace std;

char s[205];

char sta[205],top=0;

char ans[505],po=0;

int lev(char a)

void space()

int power(int a,int k)

int main()

sta[++top]=s[i];

}else

if(s[i]=='(')

else

if(s[i]==')')

space();

ans[++po]=sta[top];

space();

top--;}}

}}

while(1)

top--;

}//for(int i=1;i<=po;i++) coutint num[205],top2=0;

intpos=1;

while(pos

<=po)

pos++;

int t=1,s=0;

for(int i=l;i>=1;i--)

num[++top2]=s;

}if(ans[pos]=='+')

if(ans[pos]=='-')

if(ans[pos]=='*')

if(ans[pos]=='^')

}cout<1];

fclose(stdin);

fclose(stdout);

return

0;}

資料結構 棧實現表示式求值

expression.h calc expression 功能 利用棧實現整數表示式求值 輸入 表示式字串 輸出 求值結果 日期 2018 04 05 ifndef expression h define expression h include include include include 將中...

資料結構 表示式求值(基於棧)

博前感想 表示式求值比較難理解,特別是各種表示式的優先順序需要自己設計,還要看自己怎麼把這個優先順序的比較關係帶入到程式裡面。這裡我門可以自己寫乙個簡單的棧,也可以呼叫系統自帶的 include。塊 include include include include stack有top 獲取站頂 pus...

資料結構 表示式求值

一 實驗目的 通過乙個具體實際應用例子,加深對資料結構課程的理解,能夠綜合利用資料結構以及c語言的知識設計程式,應用到實際問題中去。二 實驗題目 常見的小型計算器可以通過輸入乙個由運算元和操作符組成的表示式計算出結構,設計乙個程式模擬上述功能。本實驗要求至少建立兩個棧和乙個運算子優先順序比較表,按照...