#include#include#include #include#define stack_init_size 100
#define increament 100
#define zuidaweishu 10
#define error 0
using namespace std;
class yunsuanfu
int get_pri()
void set_fuhao(char e)
void set_pri(int e)
yunsuanfu(char e)
yunsuanfu()
};
typedef structsqstack1;
typedef structsqstack2;
bool createstack1(sqstack1 &s)
s.stacksize = stack_init_size;
s.top = s.bottom;
return true;
} bool createstack2(sqstack2 &s)
s.stacksize = stack_init_size;
s.top = s.bottom;
return true;
} bool isempty1(sqstack1 &s)
bool isempty2(sqstack2 &s)
bool get_top1(sqstack1 &s1, int &e)
bool get_top2(sqstack2 &s2, yunsuanfu &e)
bool push1(sqstack1 &s, int &e)
*(s.top) = e;
cout<<*(s.top)<= s.stacksize)
(s.top)->set_fuhao(e.get_fuhao());//類不能直接賦值!!!
(s.top)->set_pri(e.get_pri());
s.top++;
return true;
} bool pop1(sqstack1 &s, int &e)elsewhile(yunsuanfu1.get_fuhao() != '#');
int e1;
pop1(s1,e1);
yunsuanfu e;
pop2(s2,e);
if(isempty2(s2) && isempty1(s1))elsewhile(yunsuanfu.get_pri() <= yunsuanfu1.get_pri());
push2(s2,yunsuanfu);
} }
}elseelse
} }
in.close();
} int main(){//主函式
// sqstack1 s1;//測試用
//sqstack2 s2;
//createstack1(s1);
//createstack2(s2);
//int e1 = 3;
//bool t2 = push1(s1,e1);
//cout<<"s1.top: "<<*(s1.top - 1)<
資料結構 棧實現表示式求值
expression.h calc expression 功能 利用棧實現整數表示式求值 輸入 表示式字串 輸出 求值結果 日期 2018 04 05 ifndef expression h define expression h include include include include 將中...
(複習)資料結構 棧 表示式求值
很久都沒有寫棧的程式了呢 由腦補可以字尾式求值是要用到棧的。所有說表示式求值可以分為兩部分 1.把中綴式轉換為字尾式 2.字尾式求值 include include include include include include include using namespace std char s ...
資料結構 表示式求值(基於棧)
博前感想 表示式求值比較難理解,特別是各種表示式的優先順序需要自己設計,還要看自己怎麼把這個優先順序的比較關係帶入到程式裡面。這裡我門可以自己寫乙個簡單的棧,也可以呼叫系統自帶的 include。塊 include include include include stack有top 獲取站頂 pus...