棧的基本操作及其應用 表示式求值

2021-08-13 17:50:08 字數 912 閱讀 7132

輸入乙個表示式求結果

因為程式的限制數的大小有限制

#include#include#include#include#include#includeusing namespace std;

#define maxsize 100

#define ok 1

#define error 0

#define overflow -1

typedef char selemtype;

typedef int status;

typedef struct

sqstack;

//構造乙個空棧

status initstack (sqstack &s)

//入棧

status push(sqstack &s,selemtype e)

//出棧

status pop(sqstack &s,selemtype &e)

//取棧頂元素

selemtype gettop(sqstack s)

//in

int in(char x1)

char operate(char i, char th,char j) //運算函式

return k;

}char precede( char a,char b) //比較優先順序 }

//表示式求值

char evaluateexpersion()

else

switch( precede( gettop(optr),ch) ) //比較棧頂元素和ch的優先順序

}return gettop(opnd)-'0'; //opnd棧頂元素即表示式求值結果

} int main()

{ cout<<"表示式結果為:"<

棧應用 表示式求值

include stdafx.h include using namespace std const int explenght 20 const int stack init size 20 const int stack incrment 10 templateclass stack stack...

棧應用 表示式求值

include include define length 100 初始分配棧的長度 define add len 10 棧長增量 typedef struct 定義字元棧 sqstack void initstack sqstack s 初始化乙個棧 void push sqstack s,int...

表示式求值 棧的應用

表示式求值 西西設計的機械人卡多掌握了加減法運算以後,最近又學會了一些簡單的函式求值,比如,它 知道函式min 20,23 的值是20 add 10,98 的值是108等等。經過訓練,西西設計的機械人卡多 甚至會計算一種巢狀的更複雜的表示式。假設表示式可以簡單定義為 1.乙個正的十進位制數 x 是乙...