﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-小山日志-随笔分类-Aha! Algorithm!</title><link>http://www.cppblog.com/nj-blog/category/2412.html</link><description>读书,学习与思考.</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 17:56:57 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 17:56:57 GMT</pubDate><ttl>60</ttl><item><title>将逆波兰式转换成波兰式表达式</title><link>http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Tue, 05 Dec 2006 06:45:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/16011.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/16011.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/16011.html</trackback:ping><description><![CDATA[    这是严蔚敏《数据结构》配套习题册上的题目：将逆波兰式转换成波兰式，并提示错误（作为简化，只处理"+-*/"和0~9的数字）。<br />    例如："123*-"转换成波兰式为"-1*23"<br />    逆波兰式"123*-"的表达式树如下：<br />    <img title="exp-tree" style="width: 206px; height: 166px;" src="http://docs.google.com/File?id=dddhs32p_4cztm4q" />所以这个转换过程就是：已知一个二叉树的后根遍历序列，求先根遍历序列。<br />    我的算法是根据后根遍历的序列构造一个表达式树，进而先根遍历此树获得波兰式表达式。<br />    定义了两个结构体：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 58.51%; height: 145px; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Exp{<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  op;<br />    Item  lhs;<br />    Item  rhs;<br />    Exp(){};<br />    Exp(</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> _op, Item _lhs, Item _rhs):op(_op), lhs(_lhs), rhs(_rhs){ }<br />    Exp(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Exp</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> e):op(e.op), lhs(e.lhs), rhs(e.rhs) { }<br />};<br /></span></div><br />表示一个表达式，也是表达式树上的一个子树。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 58.92%; height: 130px; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Item{<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  number;<br />    shared_ptr</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> pExp;<br />    </span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> isNumber;<br />    </span><span style="color: rgb(0, 0, 255);">explicit</span><span style="color: rgb(0, 0, 0);"> Item():isNumber(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">), number(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">), pExp(){    }<br />    Item(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Item</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> i):number(i.number), pExp(i.pExp), isNumber(i.isNumber){ }<br />};<br /></span></div><p><br />表示一个节点，它可以是一个数字，或者一个表达式（pExp这里我使用的是<a href="http://www.boost.org/">boost库</a>的智能指针shared_ptr，所以编译的话，需要先安装boost库）。<br />运行的结果如图：<br /><img src="http://www.cppblog.com/images/cppblog_com/nj-blog/2767/r_print-porland.JPG" /><br />*输入时，以'e'表示输入结束。<br />完整的代码和可执行文件点击<a class="" title="" href="/Files/nj-blog/porland.rar" target="">这里</a>下载。权当抛砖引玉了，希望有更好算法的同学赐教。<br /></p><hr />
完整的代码：<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><img id="Code_Closed_Image" onclick="this.style.display='none'; Code_Closed_Text.style.display='none'; Code_Open_Image.style.display='inline'; Code_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" height="16" width="11" /><img id="Code_Open_Image" style="display: none;" onclick="this.style.display='none'; Code_Open_Text.style.display='none'; Code_Closed_Image.style.display='inline'; Code_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" height="16" width="11" /><span id="Code_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255);"></span><span id="Code_Open_Text" style="display: none;"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">stack</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">algorithm</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">boost</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">shared_ptr.hpp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> boost::shared_ptr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Exp;<br /><img id="Codehighlighter1_178_376_Open_Image" onclick="this.style.display='none'; Codehighlighter1_178_376_Open_Text.style.display='none'; Codehighlighter1_178_376_Closed_Image.style.display='inline'; Codehighlighter1_178_376_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_178_376_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_178_376_Closed_Text.style.display='none'; Codehighlighter1_178_376_Open_Image.style.display='inline'; Codehighlighter1_178_376_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Item</span><span id="Codehighlighter1_178_376_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_178_376_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  number;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    shared_ptr</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> pExp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> isNumber;<br /><img id="Codehighlighter1_295_297_Open_Image" onclick="this.style.display='none'; Codehighlighter1_295_297_Open_Text.style.display='none'; Codehighlighter1_295_297_Closed_Image.style.display='inline'; Codehighlighter1_295_297_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_295_297_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_295_297_Closed_Text.style.display='none'; Codehighlighter1_295_297_Open_Image.style.display='inline'; Codehighlighter1_295_297_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">explicit</span><span style="color: rgb(0, 0, 0);"> Item():isNumber(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">), number(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">), pExp()</span><span id="Codehighlighter1_295_297_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_295_297_Open_Text"><span style="color: rgb(0, 0, 0);">{    }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_372_374_Open_Image" onclick="this.style.display='none'; Codehighlighter1_372_374_Open_Text.style.display='none'; Codehighlighter1_372_374_Closed_Image.style.display='inline'; Codehighlighter1_372_374_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_372_374_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_372_374_Closed_Text.style.display='none'; Codehighlighter1_372_374_Open_Image.style.display='inline'; Codehighlighter1_372_374_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Item(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Item</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> i):number(i.number), pExp(i.pExp), isNumber(i.isNumber)</span><span id="Codehighlighter1_372_374_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_372_374_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_390_572_Open_Image" onclick="this.style.display='none'; Codehighlighter1_390_572_Open_Text.style.display='none'; Codehighlighter1_390_572_Closed_Image.style.display='inline'; Codehighlighter1_390_572_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_390_572_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_390_572_Closed_Text.style.display='none'; Codehighlighter1_390_572_Open_Image.style.display='inline'; Codehighlighter1_390_572_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Exp</span><span id="Codehighlighter1_390_572_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_390_572_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  op;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item  lhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item  rhs;<br /><img id="Codehighlighter1_442_443_Open_Image" onclick="this.style.display='none'; Codehighlighter1_442_443_Open_Text.style.display='none'; Codehighlighter1_442_443_Closed_Image.style.display='inline'; Codehighlighter1_442_443_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_442_443_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_442_443_Closed_Text.style.display='none'; Codehighlighter1_442_443_Open_Image.style.display='inline'; Codehighlighter1_442_443_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Exp()</span><span id="Codehighlighter1_442_443_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_442_443_Open_Text"><span style="color: rgb(0, 0, 0);">{}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img id="Codehighlighter1_512_514_Open_Image" onclick="this.style.display='none'; Codehighlighter1_512_514_Open_Text.style.display='none'; Codehighlighter1_512_514_Closed_Image.style.display='inline'; Codehighlighter1_512_514_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_512_514_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_512_514_Closed_Text.style.display='none'; Codehighlighter1_512_514_Open_Image.style.display='inline'; Codehighlighter1_512_514_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Exp(</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> _op, Item _lhs, Item _rhs):op(_op), lhs(_lhs), rhs(_rhs)</span><span id="Codehighlighter1_512_514_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_512_514_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_568_570_Open_Image" onclick="this.style.display='none'; Codehighlighter1_568_570_Open_Text.style.display='none'; Codehighlighter1_568_570_Closed_Image.style.display='inline'; Codehighlighter1_568_570_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_568_570_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_568_570_Closed_Text.style.display='none'; Codehighlighter1_568_570_Open_Image.style.display='inline'; Codehighlighter1_568_570_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Exp(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Exp</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> e):op(e.op), lhs(e.lhs), rhs(e.rhs) </span><span id="Codehighlighter1_568_570_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_568_570_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_587_712_Open_Image" onclick="this.style.display='none'; Codehighlighter1_587_712_Open_Text.style.display='none'; Codehighlighter1_587_712_Closed_Image.style.display='inline'; Codehighlighter1_587_712_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_587_712_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_587_712_Closed_Text.style.display='none'; Codehighlighter1_587_712_Open_Image.style.display='inline'; Codehighlighter1_587_712_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Error</span><span id="Codehighlighter1_587_712_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_587_712_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> info;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">:<br /><img id="Codehighlighter1_649_651_Open_Image" onclick="this.style.display='none'; Codehighlighter1_649_651_Open_Text.style.display='none'; Codehighlighter1_649_651_Closed_Image.style.display='inline'; Codehighlighter1_649_651_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_649_651_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_649_651_Closed_Text.style.display='none'; Codehighlighter1_649_651_Open_Image.style.display='inline'; Codehighlighter1_649_651_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Error(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> _info):info(_info)</span><span id="Codehighlighter1_649_651_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_649_651_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_673_675_Open_Image" onclick="this.style.display='none'; Codehighlighter1_673_675_Open_Text.style.display='none'; Codehighlighter1_673_675_Closed_Image.style.display='inline'; Codehighlighter1_673_675_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_673_675_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_673_675_Closed_Text.style.display='none'; Codehighlighter1_673_675_Open_Image.style.display='inline'; Codehighlighter1_673_675_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Error():info(</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">)</span><span id="Codehighlighter1_673_675_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_673_675_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_694_707_Open_Image" onclick="this.style.display='none'; Codehighlighter1_694_707_Open_Text.style.display='none'; Codehighlighter1_694_707_Closed_Image.style.display='inline'; Codehighlighter1_694_707_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_694_707_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_694_707_Closed_Text.style.display='none'; Codehighlighter1_694_707_Open_Image.style.display='inline'; Codehighlighter1_694_707_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> what()</span><span id="Codehighlighter1_694_707_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_694_707_Open_Text"><span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> info;}</span></span><span style="color: rgb(0, 0, 0);">   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_743_936_Open_Image" onclick="this.style.display='none'; Codehighlighter1_743_936_Open_Text.style.display='none'; Codehighlighter1_743_936_Closed_Image.style.display='inline'; Codehighlighter1_743_936_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_743_936_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_743_936_Closed_Text.style.display='none'; Codehighlighter1_743_936_Open_Image.style.display='inline'; Codehighlighter1_743_936_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> printPorland(Exp</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> exp)</span><span id="Codehighlighter1_743_936_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_743_936_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> exp.op ;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(exp.lhs.isNumber)  cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> exp.lhs.number;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> printPorland(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">exp.lhs.pExp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(exp.rhs.isNumber)  cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> exp.rhs.number;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> printPorland(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">exp.rhs.pExp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> main()<br /><img id="Codehighlighter1_950_2397_Open_Image" onclick="this.style.display='none'; Codehighlighter1_950_2397_Open_Text.style.display='none'; Codehighlighter1_950_2397_Closed_Image.style.display='inline'; Codehighlighter1_950_2397_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_950_2397_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_950_2397_Closed_Text.style.display='none'; Codehighlighter1_950_2397_Open_Image.style.display='inline'; Codehighlighter1_950_2397_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_950_2397_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_950_2397_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    stack</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Item</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">  ExpStack;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpItem;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpLhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpRhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">  numbers </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">0123456789</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">  operators </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+-*/</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Input the Express(输入 'e'标识结束):</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><img id="Codehighlighter1_1165_2336_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1165_2336_Open_Text.style.display='none'; Codehighlighter1_1165_2336_Closed_Image.style.display='inline'; Codehighlighter1_1165_2336_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1165_2336_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1165_2336_Closed_Text.style.display='none'; Codehighlighter1_1165_2336_Open_Image.style.display='inline'; Codehighlighter1_1165_2336_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">do</span><span id="Codehighlighter1_1165_2336_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1165_2336_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img id="Codehighlighter1_1171_2183_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1171_2183_Open_Text.style.display='none'; Codehighlighter1_1171_2183_Closed_Image.style.display='inline'; Codehighlighter1_1171_2183_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1171_2183_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1171_2183_Closed_Text.style.display='none'; Codehighlighter1_1171_2183_Open_Image.style.display='inline'; Codehighlighter1_1171_2183_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">try</span><span id="Codehighlighter1_1171_2183_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1171_2183_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img id="Codehighlighter1_1194_1966_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1194_1966_Open_Text.style.display='none'; Codehighlighter1_1194_1966_Closed_Image.style.display='inline'; Codehighlighter1_1194_1966_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1194_1966_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1194_1966_Closed_Text.style.display='none'; Codehighlighter1_1194_1966_Open_Image.style.display='inline'; Codehighlighter1_1194_1966_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(cin</span><span style="color: rgb(0, 0, 0);">&gt;&gt;</span><span style="color: rgb(0, 0, 0);">tmpChar)</span><span id="Codehighlighter1_1194_1966_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1194_1966_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tmpChar </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">e</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">e为结束符</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(find(numbers.begin(), numbers.end(),  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">是一个数字</span><span style="color: rgb(0, 128, 0);"><br /><img id="Codehighlighter1_1320_1421_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1320_1421_Open_Text.style.display='none'; Codehighlighter1_1320_1421_Closed_Image.style.display='inline'; Codehighlighter1_1320_1421_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1320_1421_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1320_1421_Closed_Text.style.display='none'; Codehighlighter1_1320_1421_Open_Image.style.display='inline'; Codehighlighter1_1320_1421_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                    tmpChar)</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">numbers.end())</span><span id="Codehighlighter1_1320_1421_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1320_1421_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpItem.isNumber </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpItem.number   </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.push(tmpItem);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">数字入栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(find(operators.begin(), operators.end(), </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">是一个操作符</span><span style="color: rgb(0, 128, 0);"><br /><img id="Codehighlighter1_1511_1903_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1511_1903_Open_Text.style.display='none'; Codehighlighter1_1511_1903_Closed_Image.style.display='inline'; Codehighlighter1_1511_1903_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1511_1903_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1511_1903_Closed_Text.style.display='none'; Codehighlighter1_1511_1903_Open_Image.style.display='inline'; Codehighlighter1_1511_1903_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                    tmpChar)</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">operators.end())</span><span id="Codehighlighter1_1511_1903_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1511_1903_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">操作符每次要对应两个被操作数，否则语法错误</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(ExpStack.size()</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> Error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Syntactic Error!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">操作符两边的元素出栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                tmpRhs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExpStack.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpLhs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExpStack.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpItem.isNumber </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">非数字，是一个表达式</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                tmpItem.pExp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> shared_ptr</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Exp(tmpChar, tmpLhs, tmpRhs)); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.push(tmpItem);     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">表达式入栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                           <br /><img id="Codehighlighter1_1909_1962_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1909_1962_Open_Text.style.display='none'; Codehighlighter1_1909_1962_Closed_Image.style.display='inline'; Codehighlighter1_1909_1962_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1909_1962_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1909_1962_Closed_Text.style.display='none'; Codehighlighter1_1909_1962_Open_Image.style.display='inline'; Codehighlighter1_1909_1962_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span id="Codehighlighter1_1909_1962_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1909_1962_Open_Text"><span style="color: rgb(0, 0, 0);">{  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 未知字符</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);">  Error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Unknow Character!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(ExpStack.size()</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> Error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Syntactic Error!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tmpItem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExpStack.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ExpStack.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tmpItem.isNumber) cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> tmpItem.number </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> printPorland(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">tmpItem.pExp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_2199_2277_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2199_2277_Open_Text.style.display='none'; Codehighlighter1_2199_2277_Closed_Image.style.display='inline'; Codehighlighter1_2199_2277_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2199_2277_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_2199_2277_Closed_Text.style.display='none'; Codehighlighter1_2199_2277_Open_Image.style.display='inline'; Codehighlighter1_2199_2277_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    }</span></span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(Error</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> e)</span><span id="Codehighlighter1_2199_2277_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_2199_2277_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> e.what() </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getline(cin, </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">());        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">跳过错误的当前行</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">    }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Try again?(y/n)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cin </span><span style="color: rgb(0, 0, 0);">&gt;&gt;</span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(tmpChar </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">y</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> tmpChar </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Y</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></span></div><img src ="http://www.cppblog.com/nj-blog/aggbug/16011.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-12-05 14:45 <a href="http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>