page265.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 36 行
HTML
36 行
<HTML><HEAD><TITLE>Prefix Notation</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="tex2html4253" HREF="page266.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4251" HREF="page263.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4245" HREF="page264.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4255" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION009502000000000000000">Prefix Notation</A></H3><P>In prefix notation<A NAME=15461> </A> the operator is writtenbefore its operands.Therefore, in order to print the prefix expression from an expression tree,preorder traversal is done.That is, at every non-terminal node we do the following:<OL><LI> Print the root; and then<LI> print a left parenthesis; and then<LI> traverse the left subtree; and then<LI> print a comma; and then<LI> traverse the right subtree; and then<LI> print a right parenthesis.</OL>If we use this procedure to print the tree givenin Figure <A HREF="page263.html#figtree6"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> we get the prefix expression<P><A NAME="eqntreesprefix"> </A> <IMG WIDTH=500 HEIGHT=16 ALIGN=BOTTOM ALT="equation15465" SRC="img1105.gif" ><P>While this notation may appear unfamiliar at first,consider the result obtained when we spell out the names of the operators:<PRE>__add__(__div__(a,b), __mul__(__sub__(c,d), e))</PRE>This is precisely the notation used in a Python programto invoke user defined methods<tt>__add__</tt>, <tt>__sub__</tt>, <tt>__mul__</tt> and <tt>__div__</tt>.<P><HR><A NAME="tex2html4253" HREF="page266.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4251" HREF="page263.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4245" HREF="page264.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4255" 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 © 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 + -
显示快捷键?