栈
0.1
数据结构_第3章
|
#include <Rpn.hh>
Classes | |
struct | Item |
< 后缀式的元素: 操作数, 操作符 More... | |
Public Member Functions | |
Rpn_t (const std::string &expr_str="0.0", notationType exprType=notationType::Infix) | |
Construct a new Rpn_t object. More... | |
~Rpn_t ()=default | |
Destroy the Rpn_t object. More... | |
double | calcVal () const |
计算(后缀)表达式的值 More... | |
std::string | postfix () const |
获取后缀形式的string More... | |
Rpn_t & | assign (const std::string &expr_str, notationType _type=notationType::Infix) |
设置Rpn_t类对象的值 More... | |
Private Member Functions | |
Item | stoItem (const char *_ch, const char **_EndPtr=nullptr) const |
Rpn类的工具函数 More... | |
std::string | itemToStr (const Item &Op) const |
获取表示项(操作符/操作数)的string More... | |
List::dLinkList< Item > | exprStrToList (const std::string &exprStr) const |
用string中的表达式创建一个list More... | |
List::dLinkList< Item > | infixListToPostfixList (const List::dLinkList< Item > &infixList) const |
用一个中缀list创建一个后缀list More... | |
std::string | itemListToStr (const List::dLinkList< Item > &itemList) const |
获取表示itemList的string More... | |
Private Attributes | |
List::dLinkList< Item > | itemList |
存储后缀表达式的双链表 More... | |
std::string | postfixStr |
存储后缀形式的字符串 More... | |
Friends | |
bool | operator== (const Item &lhs, const Item &rhs) |
operator== More... | |
|
explicit |
Construct a new Rpn_t object.
expr_str | |
exprType |
Definition at line 375 of file Rpn.hh.
References exprStrToList(), infixListToPostfixList(), itemList, itemListToStr(), RPN::Postfix, and postfixStr.
|
default |
Destroy the Rpn_t object.
Rpn_t & RPN::Rpn_t::assign | ( | const std::string & | expr_str, |
notationType | _type = notationType::Infix |
||
) |
设置Rpn_t类对象的值
expr_str | |
_type |
Definition at line 396 of file Rpn.hh.
References exprStrToList(), infixListToPostfixList(), itemList, itemListToStr(), RPN::Postfix, and postfixStr.
Referenced by main().
double RPN::Rpn_t::calcVal | ( | ) | const |
计算(后缀)表达式的值
Definition at line 587 of file Rpn.hh.
References RPN::Rpn_t::Item::excOp(), Stack::seqStack< T >::isEmpty(), itemList, RPN::Rpn_t::Item::operand_val, Stack::seqStack< T >::pop(), and Stack::seqStack< T >::push().
Referenced by main().
|
private |
|
private |
用一个中缀list创建一个后缀list
infixList |
Definition at line 508 of file Rpn.hh.
References List::dLinkList< T >::begin(), RPN::Rpn_t::Item::Cparen, List::dLinkList< T >::end(), RPN::Rpn_t::Item::Exp, RPN::Rpn_t::Item::hasLoPriThan(), RPN::Rpn_t::Item::isNAO(), RPN::Rpn_t::Item::nao(), RPN::Rpn_t::Item::Oparen, RPN::Rpn_t::Item::operator_type, Stack::linkStack< T >::pop(), RPN::Rpn_t::Item::priOfAdd, RPN::Rpn_t::Item::priOfMul, RPN::Rpn_t::Item::priority(), Stack::linkStack< T >::push(), List::dLinkList< T >::push_back(), and Stack::linkStack< T >::top().
Referenced by assign(), and Rpn_t().
|
private |
|
private |
获取表示项(操作符/操作数)的string
Op |
Definition at line 640 of file Rpn.hh.
References RPN::Rpn_t::Item::Add, RPN::buf_size, RPN::Rpn_t::Item::Cparen, RPN::Rpn_t::Item::Div, RPN::Rpn_t::Item::Exp, RPN::Rpn_t::Item::item_type, RPN::Rpn_t::Item::Mul, RPN::Rpn_t::Item::Oparen, RPN::Rpn_t::Item::Operand, RPN::Rpn_t::Item::operand_val, RPN::Rpn_t::Item::operator_type, and RPN::Rpn_t::Item::Sub.
Referenced by itemListToStr().
std::string RPN::Rpn_t::postfix | ( | ) | const |
获取后缀形式的string
Definition at line 421 of file Rpn.hh.
References postfixStr.
Referenced by main().
|
private |
Rpn类的工具函数
从string首解析一个项(操作符/操作数)
_ch | |
_EndPtr |
Definition at line 427 of file Rpn.hh.
References RPN::Rpn_t::Item::Add, RPN::Rpn_t::Item::Cparen, RPN::Rpn_t::Item::Div, RPN::Rpn_t::Item::Exp, RPN::Rpn_t::Item::Mul, RPN::Rpn_t::Item::NAO, RPN::Rpn_t::Item::Oparen, RPN::Rpn_t::Item::Operand, RPN::Rpn_t::Item::Operator, and RPN::Rpn_t::Item::Sub.
Referenced by exprStrToList().
|
private |
存储后缀表达式的双链表
Definition at line 286 of file Rpn.hh.
Referenced by assign(), calcVal(), exprStrToList(), itemListToStr(), and Rpn_t().
|
private |