資源簡介
逆波蘭表達式的C++實現(xiàn),用類封裝,用于計算逆波蘭表達式
代碼片段和文件信息
#include?“Rpn.h“
Rpn::Rpn(char?exp[])
{
????pst?=?0;
????strcpy(expression?exp);
????length?=?strlen(expression);?
}
bool?Rpn::isoperator(char?ch)
{
????switch(ch)
????{
????????case?‘+‘:
????????case?‘-‘:
????????case?‘*‘:
????????case?‘/‘:
????????????return?true;
????????default:
????????????return?false;
????}
}
bool?Rpn::isnumber(char?ch)
{
????return?(isdigit(expression[pst])?||?expression[pst]?==?‘.‘);
}
void?Rpn::pushNextNumber()
{
????char?number[48];????//用于提取數(shù)字的字符串?
????number[0]?=?expression[pst];????//將第一位賦值為當(dāng)前數(shù)字字符?
????pst++;
????int?number_place?=?1;????//數(shù)字位數(shù)(number數(shù)組寫入位置)?
????while?((pst?pression[pst])))????//當(dāng)讀取位置不小于長度并且表當(dāng)前位是數(shù)字時?
????{
????????number[number_place]?=?expression[pst];
????????number_place++
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4005??2010-11-16?13:37??Rpn\Rpn.cpp
?????文件???????3423??2010-11-15?23:21??Rpn\Rpn.dsp
?????文件????????529??2010-11-15?23:21??Rpn\Rpn.dsw
?????文件????????902??2010-11-16?13:25??Rpn\Rpn.h
?????文件???????1126??2010-11-18?09:38??Rpn\Rpn.plg
?????目錄??????????0??2010-12-03?13:11??Rpn
-----------?---------??----------?-----??----
?????????????????9985????????????????????6
- 上一篇:八數(shù)碼C實現(xiàn)
- 下一篇:編譯原理求firstfollow集合
評論
共有 條評論