栈  0.1
数据结构_第3章
RPN::Rpn_t Class Reference

#include <Rpn.hh>

Collaboration diagram for RPN::Rpn_t:
[legend]

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_tassign (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< ItemexprStrToList (const std::string &exprStr) const
 用string中的表达式创建一个list More...
 
List::dLinkList< IteminfixListToPostfixList (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< ItemitemList
 存储后缀表达式的双链表 More...
 
std::string postfixStr
 存储后缀形式的字符串 More...
 

Friends

bool operator== (const Item &lhs, const Item &rhs)
 operator== More...
 

Detailed Description

Definition at line 126 of file Rpn.hh.

Constructor & Destructor Documentation

◆ Rpn_t()

RPN::Rpn_t::Rpn_t ( const std::string &  expr_str = "0.0",
notationType  exprType = notationType::Infix 
)
explicit

Construct a new Rpn_t object.

Parameters
expr_str
exprType

Definition at line 375 of file Rpn.hh.

References exprStrToList(), infixListToPostfixList(), itemList, itemListToStr(), RPN::Postfix, and postfixStr.

Here is the call graph for this function:

◆ ~Rpn_t()

RPN::Rpn_t::~Rpn_t ( )
default

Destroy the Rpn_t object.

Member Function Documentation

◆ assign()

Rpn_t & RPN::Rpn_t::assign ( const std::string &  expr_str,
notationType  _type = notationType::Infix 
)

设置Rpn_t类对象的值

Parameters
expr_str
_type
Returns
Rpn_t&

Definition at line 396 of file Rpn.hh.

References exprStrToList(), infixListToPostfixList(), itemList, itemListToStr(), RPN::Postfix, and postfixStr.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calcVal()

double RPN::Rpn_t::calcVal ( ) const

计算(后缀)表达式的值

Returns
double

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exprStrToList()

List::dLinkList< Rpn_t::Item > RPN::Rpn_t::exprStrToList ( const std::string &  exprStr) const
private

用string中的表达式创建一个list

Parameters
exprStr
Returns
List::dLinkList<Item>

Definition at line 492 of file Rpn.hh.

References itemList, and stoItem().

Referenced by assign(), and Rpn_t().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ infixListToPostfixList()

List::dLinkList< Rpn_t::Item > RPN::Rpn_t::infixListToPostfixList ( const List::dLinkList< Item > &  infixList) const
private

用一个中缀list创建一个后缀list

Parameters
infixList
Returns
List::dLinkList<Item>

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ itemListToStr()

std::string RPN::Rpn_t::itemListToStr ( const List::dLinkList< Item > &  itemList) const
private

获取表示itemList的string

Parameters
itemList
Returns
std::string

Definition at line 627 of file Rpn.hh.

References itemList, and itemToStr().

Referenced by assign(), and Rpn_t().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ itemToStr()

std::string RPN::Rpn_t::itemToStr ( const Item Op) const
private

获取表示项(操作符/操作数)的string

Parameters
Op
Returns
std::string

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().

Here is the caller graph for this function:

◆ postfix()

std::string RPN::Rpn_t::postfix ( ) const

获取后缀形式的string

Returns
std::string

Definition at line 421 of file Rpn.hh.

References postfixStr.

Referenced by main().

Here is the caller graph for this function:

◆ stoItem()

Rpn_t::Item RPN::Rpn_t::stoItem ( const char *  _ch,
const char **  _EndPtr = nullptr 
) const
private

Rpn类的工具函数

从string首解析一个项(操作符/操作数)

Parameters
_ch
_EndPtr
Returns
Item

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().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator==

bool operator== ( const Item lhs,
const Item rhs 
)
friend

operator==

Parameters
lhs
rhs
Returns
true
false

Definition at line 740 of file Rpn.hh.

Member Data Documentation

◆ itemList

List::dLinkList<Item> RPN::Rpn_t::itemList
private

存储后缀表达式的双链表

Definition at line 286 of file Rpn.hh.

Referenced by assign(), calcVal(), exprStrToList(), itemListToStr(), and Rpn_t().

◆ postfixStr

std::string RPN::Rpn_t::postfixStr
private

存储后缀形式的字符串

Definition at line 291 of file Rpn.hh.

Referenced by assign(), postfix(), and Rpn_t().


The documentation for this class was generated from the following file: