page145.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 39 行

HTML
39
字号
<HTML><HEAD><TITLE>Evaluating Postfix Expressions</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html2879" HREF="page146.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2877" HREF="page144.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2871" HREF="page144.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2881" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION006131000000000000000">Evaluating Postfix Expressions</A></H3><P>One of the most useful characteristics of a postfix expressionis that the value of such an expression can be computed easilywith the aid of a stack of values.The components of a postfix expression are processedfrom left to right as follows:<OL><LI> If the next component of the expression is an operand,	the value of the component is pushed onto the stack.<LI> If the next component of the expression is an operator,	then its operands are in the stack.	The required number of operands are popped from the stack;	the specified operation is performed;	and the result is pushed back onto the stack.</OL>After all the components of the expression have been processed in this fashion,the stack will contain a single resultwhich is the final value of the expression.Figure&nbsp;<A HREF="page145.html#figrpn"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> illustrates the use of a stackto evaluate the RPN expression given in Equation&nbsp;<A HREF="page144.html#eqnstacksrpn"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="5993">&#160;</A><A NAME="figrpn">&#160;</A> <IMG WIDTH=575 HEIGHT=245 ALIGN=BOTTOM ALT="figure5592" SRC="img685.gif"  ><BR><STRONG>Figure:</STRONG> Evaluating the RPN expression 	in Equation&nbsp;<A HREF="page144.html#eqnstacksrpn"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> using a stack.<BR><P><HR><A NAME="tex2html2879" HREF="page146.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2877" HREF="page144.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2871" HREF="page144.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2881" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright &#169; 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?