表示式求值的另一種方法

2021-09-08 21:54:58 字數 1093 閱讀 5973

表示式求值除了用文法實現之外,還可以直接用棧,將中綴表示式轉化為字尾表示式。然後再用求表示式的值就輕而易舉了。

下面貼程式原始碼:(可能有點長,呵呵:)

main.cpp

#include"stack.cpp"

#include"stack.h"

#includeusing namespace std;

/** 該函式有兩個功能

* 1. 輸入中綴表示式

* 2. 將中綴表示式轉化為字尾表示式

* 形參為兩個指標分別指向兩個陣列(乙個儲存數字,乙個儲存運算子)

* 返回值是數字和運算子的總個數(若轉化出錯,返回-1)

*/int change(double *darra,char *carra)

else //如果是運算子

templatebool stack::isempty() // if the stack is empty, return true; otherwise return false.

else }

templatevoid stack::pop() // pop an element from the top of the stack

template// clear all the elements in the stack

void stack::clear()

#endif

stack.h

/*

* 模板類(棧)

*/#ifndef stack_h

#define stack_h

#define s_size 50 //the size of the stack

templateclass stack

;#endif

執行結果:

動態XtraReports的另一種方法

昨晚一下忘了,昨天在一籌莫展的情況下,有一位好心 小土豆 遠端協助,實操指導了另外一種動態xtrareports方法。因為是他幫我寫的 我就不貼了。簡單說一下方法思路。在xtrareports資料欄內加入乙個gridcontrol1,將其dock設為fill。然後還是在xtrareports的建構函...

SQL 擷取的另一種方法

有時候我們需要將如下結果集中的ids進行分割 ids 1,12,123 1 行受影響 希望得到這樣的結果 112 123 3 行受影響 之前一直用表值函式來擷取,這裡借助master.dbo.spt values表來實現 準備資料 if object id tempdb.a is notnull d...

使索引失效的另一種方法

使索引失效的另一種方法 我們可以使用hints使索引失效,但有時候我們可以使用另外一種方法來更靈活的限制索引的使用。假設我們有表test id number,name varchar 20 在表上建立了索引ix test id,ix test name。在表上的資料有 sql select from...