﻿<?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++博客-I need time----------------&gt;         Hsssssss@C++-文章分类-C++代码</title><link>http://www.cppblog.com/dotaqop/category/16928.html</link><description>每天进步一...................................</description><language>zh-cn</language><lastBuildDate>Sat, 24 Sep 2011 06:17:12 GMT</lastBuildDate><pubDate>Sat, 24 Sep 2011 06:17:12 GMT</pubDate><ttl>60</ttl><item><title>I am hs-----------&gt;hs am I</title><link>http://www.cppblog.com/dotaqop/articles/155745.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Wed, 14 Sep 2011 05:39:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/155745.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/155745.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/155745.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/155745.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/155745.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_78_235_Open_Image" onclick="this.style.display='none'; Codehighlighter1_78_235_Open_Text.style.display='none'; Codehighlighter1_78_235_Closed_Image.style.display='inline'; Codehighlighter1_78_235_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_78_235_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_78_235_Closed_Text.style.display='none'; Codehighlighter1_78_235_Open_Image.style.display='inline'; Codehighlighter1_78_235_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Reverse(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pBegin,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pEnd)</span><span id="Codehighlighter1_78_235_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_78_235_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(pBegin&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;pEnd&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL)<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_150_233_Open_Image" onclick="this.style.display='none'; Codehighlighter1_150_233_Open_Text.style.display='none'; Codehighlighter1_150_233_Closed_Image.style.display='inline'; Codehighlighter1_150_233_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_150_233_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_150_233_Closed_Text.style.display='none'; Codehighlighter1_150_233_Open_Image.style.display='inline'; Codehighlighter1_150_233_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(pBegin&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;pEnd)</span><span id="Codehighlighter1_150_233_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_150_233_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;temp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pBegin;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pBegin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pEnd;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pEnd&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;temp;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBegin</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnd</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_272_644_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_644_Open_Text.style.display='none'; Codehighlighter1_272_644_Closed_Image.style.display='inline'; Codehighlighter1_272_644_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_272_644_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_272_644_Closed_Text.style.display='none'; Codehighlighter1_272_644_Open_Image.style.display='inline'; Codehighlighter1_272_644_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">ReverseSentence(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pData)</span><span id="Codehighlighter1_272_644_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_272_644_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(pData&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL)<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;NULL;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pBegin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pData;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pEnd&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pData;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">*</span><span style="color: #000000">pEnd&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">)<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnd</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pEnd</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Reverse(pBegin,pEnd);<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pEnd&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pData;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_459_627_Open_Image" onclick="this.style.display='none'; Codehighlighter1_459_627_Open_Text.style.display='none'; Codehighlighter1_459_627_Closed_Image.style.display='inline'; Codehighlighter1_459_627_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_459_627_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_459_627_Closed_Text.style.display='none'; Codehighlighter1_459_627_Open_Image.style.display='inline'; Codehighlighter1_459_627_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">*</span><span style="color: #000000">pBegin&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span id="Codehighlighter1_459_627_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_459_627_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_482_510_Open_Image" onclick="this.style.display='none'; Codehighlighter1_482_510_Open_Text.style.display='none'; Codehighlighter1_482_510_Closed_Image.style.display='inline'; Codehighlighter1_482_510_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_482_510_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_482_510_Closed_Text.style.display='none'; Codehighlighter1_482_510_Open_Image.style.display='inline'; Codehighlighter1_482_510_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">*</span><span style="color: #000000">pBegin&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span id="Codehighlighter1_482_510_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_482_510_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBegin</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnd</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_554_605_Open_Image" onclick="this.style.display='none'; Codehighlighter1_554_605_Open_Text.style.display='none'; Codehighlighter1_554_605_Closed_Image.style.display='inline'; Codehighlighter1_554_605_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_554_605_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_554_605_Closed_Text.style.display='none'; Codehighlighter1_554_605_Open_Image.style.display='inline'; Codehighlighter1_554_605_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">*</span><span style="color: #000000">pEnd&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pEnd&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span id="Codehighlighter1_554_605_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_554_605_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reverse(pBegin,</span><span style="color: #000000">--</span><span style="color: #000000">pEnd);<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBegin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">pEnd;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnd</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;pData;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img id="Codehighlighter1_658_767_Open_Image" onclick="this.style.display='none'; Codehighlighter1_658_767_Open_Text.style.display='none'; Codehighlighter1_658_767_Closed_Image.style.display='inline'; Codehighlighter1_658_767_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_658_767_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_658_767_Closed_Text.style.display='none'; Codehighlighter1_658_767_Open_Image.style.display='inline'; Codehighlighter1_658_767_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_658_767_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_658_767_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str[]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">I&nbsp;am&nbsp;hs</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">str</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ReverseSentence(str)</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/155745.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-09-14 13:39 <a href="http://www.cppblog.com/dotaqop/articles/155745.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二叉树非递归 层次遍历</title><link>http://www.cppblog.com/dotaqop/articles/153728.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Thu, 18 Aug 2011 07:44:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/153728.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/153728.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/153728.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/153728.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/153728.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">queue</span><span style="color: #000000">&gt;</span><span style="color: #008000">//</span><span style="color: #008000">队列</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img id="Codehighlighter1_79_133_Open_Image" onclick="this.style.display='none'; Codehighlighter1_79_133_Open_Text.style.display='none'; Codehighlighter1_79_133_Closed_Image.style.display='inline'; Codehighlighter1_79_133_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_79_133_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_79_133_Closed_Text.style.display='none'; Codehighlighter1_79_133_Open_Image.style.display='inline'; Codehighlighter1_79_133_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;BinTreeNode</span><span id="Codehighlighter1_79_133_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_79_133_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">left;<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">right;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_165_420_Open_Image" onclick="this.style.display='none'; Codehighlighter1_165_420_Open_Text.style.display='none'; Codehighlighter1_165_420_Closed_Image.style.display='inline'; Codehighlighter1_165_420_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_165_420_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_165_420_Closed_Text.style.display='none'; Codehighlighter1_165_420_Open_Image.style.display='inline'; Codehighlighter1_165_420_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;level(BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">root)</span><span id="Codehighlighter1_165_420_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_165_420_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">层次遍历</span><span style="color: #008000"><br /></span><span style="color: #008080">11</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;queue</span><span style="color: #000000">&lt;</span><span style="color: #000000">BinTreeNode</span><span style="color: #000000">*&gt;</span><span style="color: #000000">&nbsp;q;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;q.push(tmp);<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_261_418_Open_Image" onclick="this.style.display='none'; Codehighlighter1_261_418_Open_Text.style.display='none'; Codehighlighter1_261_418_Closed_Image.style.display='inline'; Codehighlighter1_261_418_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_261_418_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_261_418_Closed_Text.style.display='none'; Codehighlighter1_261_418_Open_Image.style.display='inline'; Codehighlighter1_261_418_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">q.empty())</span><span id="Codehighlighter1_261_418_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_261_418_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;q.front();<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">left&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;NULL)<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.push(tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">left);<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">right&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;NULL)<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.push(tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">right);<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.pop();<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/153728.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-08-18 15:44 <a href="http://www.cppblog.com/dotaqop/articles/153728.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二叉树非递归 后序遍历</title><link>http://www.cppblog.com/dotaqop/articles/153727.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Thu, 18 Aug 2011 07:32:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/153727.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/153727.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/153727.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/153727.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/153727.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stack</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img id="Codehighlighter1_75_129_Open_Image" onclick="this.style.display='none'; Codehighlighter1_75_129_Open_Text.style.display='none'; Codehighlighter1_75_129_Closed_Image.style.display='inline'; Codehighlighter1_75_129_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_75_129_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_75_129_Closed_Text.style.display='none'; Codehighlighter1_75_129_Open_Image.style.display='inline'; Codehighlighter1_75_129_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;BinTreeNode</span><span id="Codehighlighter1_75_129_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_75_129_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">left;<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">right;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_144_148_Open_Image" onclick="this.style.display='none'; Codehighlighter1_144_148_Open_Text.style.display='none'; Codehighlighter1_144_148_Closed_Image.style.display='inline'; Codehighlighter1_144_148_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_144_148_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_144_148_Closed_Text.style.display='none'; Codehighlighter1_144_148_Open_Image.style.display='inline'; Codehighlighter1_144_148_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">enum</span><span style="color: #000000">&nbsp;tagtype</span><span id="Codehighlighter1_144_148_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_144_148_Open_Text"><span style="color: #000000">{L,R}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_167_202_Open_Image" onclick="this.style.display='none'; Codehighlighter1_167_202_Open_Text.style.display='none'; Codehighlighter1_167_202_Closed_Image.style.display='inline'; Codehighlighter1_167_202_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_167_202_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_167_202_Closed_Text.style.display='none'; Codehighlighter1_167_202_Open_Image.style.display='inline'; Codehighlighter1_167_202_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;StackElem</span><span id="Codehighlighter1_167_202_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_167_202_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">ptr;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;tagtype&nbsp;tag;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_239_589_Open_Image" onclick="this.style.display='none'; Codehighlighter1_239_589_Open_Text.style.display='none'; Codehighlighter1_239_589_Closed_Image.style.display='inline'; Codehighlighter1_239_589_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_239_589_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_239_589_Closed_Text.style.display='none'; Codehighlighter1_239_589_Open_Image.style.display='inline'; Codehighlighter1_239_589_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;PostOrder(BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">root)</span><span id="Codehighlighter1_239_589_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_239_589_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;stack</span><span style="color: #000000">&lt;</span><span style="color: #000000">StackElem</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;s;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;StackElem&nbsp;x;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_333_587_Open_Image" onclick="this.style.display='none'; Codehighlighter1_333_587_Open_Text.style.display='none'; Codehighlighter1_333_587_Closed_Image.style.display='inline'; Codehighlighter1_333_587_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_333_587_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_333_587_Closed_Text.style.display='none'; Codehighlighter1_333_587_Open_Image.style.display='inline'; Codehighlighter1_333_587_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_333_587_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_333_587_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_355_423_Open_Image" onclick="this.style.display='none'; Codehighlighter1_355_423_Open_Text.style.display='none'; Codehighlighter1_355_423_Closed_Image.style.display='inline'; Codehighlighter1_355_423_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_355_423_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_355_423_Closed_Text.style.display='none'; Codehighlighter1_355_423_Open_Image.style.display='inline'; Codehighlighter1_355_423_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;NULL)</span><span id="Codehighlighter1_355_423_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_355_423_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.ptr&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tmp;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.tag&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;L;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.push(x);<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_464_513_Open_Image" onclick="this.style.display='none'; Codehighlighter1_464_513_Open_Text.style.display='none'; Codehighlighter1_464_513_Closed_Image.style.display='inline'; Codehighlighter1_464_513_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_464_513_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_464_513_Closed_Text.style.display='none'; Codehighlighter1_464_513_Open_Image.style.display='inline'; Codehighlighter1_464_513_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty()&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;s.top().tag&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;R)</span><span id="Codehighlighter1_464_513_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_464_513_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">s.top().ptr</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.pop();<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_531_584_Open_Image" onclick="this.style.display='none'; Codehighlighter1_531_584_Open_Text.style.display='none'; Codehighlighter1_531_584_Closed_Image.style.display='inline'; Codehighlighter1_531_584_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_531_584_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_531_584_Closed_Text.style.display='none'; Codehighlighter1_531_584_Open_Image.style.display='inline'; Codehighlighter1_531_584_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_531_584_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_531_584_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.top().tag&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;R;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;s.top().ptr</span><span style="color: #000000">-&gt;</span><span style="color: #000000">right;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/153727.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-08-18 15:32 <a href="http://www.cppblog.com/dotaqop/articles/153727.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二叉树非递归 先序，中序</title><link>http://www.cppblog.com/dotaqop/articles/153724.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Thu, 18 Aug 2011 07:14:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/153724.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/153724.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/153724.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/153724.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/153724.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stack</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img id="Codehighlighter1_75_129_Open_Image" onclick="this.style.display='none'; Codehighlighter1_75_129_Open_Text.style.display='none'; Codehighlighter1_75_129_Closed_Image.style.display='inline'; Codehighlighter1_75_129_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_75_129_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_75_129_Closed_Text.style.display='none'; Codehighlighter1_75_129_Open_Image.style.display='inline'; Codehighlighter1_75_129_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;BinTreeNode</span><span id="Codehighlighter1_75_129_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_75_129_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">left;<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">right;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_165_400_Open_Image" onclick="this.style.display='none'; Codehighlighter1_165_400_Open_Text.style.display='none'; Codehighlighter1_165_400_Closed_Image.style.display='inline'; Codehighlighter1_165_400_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_165_400_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_165_400_Closed_Text.style.display='none'; Codehighlighter1_165_400_Open_Image.style.display='inline'; Codehighlighter1_165_400_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;preOrder1(BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">root)</span><span id="Codehighlighter1_165_400_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_165_400_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">先序1</span><span style="color: #008000"><br /></span><span style="color: #008080">11</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;stack</span><span style="color: #000000">&lt;</span><span style="color: #000000">BinTreeNode</span><span style="color: #000000">*&gt;</span><span style="color: #000000">&nbsp;s;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">tmp</span><span style="color: #000000">=</span><span style="color: #000000">root;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_251_398_Open_Image" onclick="this.style.display='none'; Codehighlighter1_251_398_Open_Text.style.display='none'; Codehighlighter1_251_398_Closed_Image.style.display='inline'; Codehighlighter1_251_398_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_251_398_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_251_398_Closed_Text.style.display='none'; Codehighlighter1_251_398_Open_Image.style.display='inline'; Codehighlighter1_251_398_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_251_398_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_251_398_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_271_336_Open_Image" onclick="this.style.display='none'; Codehighlighter1_271_336_Open_Text.style.display='none'; Codehighlighter1_271_336_Closed_Image.style.display='inline'; Codehighlighter1_271_336_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_271_336_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_271_336_Closed_Text.style.display='none'; Codehighlighter1_271_336_Open_Image.style.display='inline'; Codehighlighter1_271_336_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_271_336_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_271_336_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.push(tmp);<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">left;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_354_395_Open_Image" onclick="this.style.display='none'; Codehighlighter1_354_395_Open_Text.style.display='none'; Codehighlighter1_354_395_Closed_Image.style.display='inline'; Codehighlighter1_354_395_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_354_395_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_354_395_Closed_Text.style.display='none'; Codehighlighter1_354_395_Open_Image.style.display='inline'; Codehighlighter1_354_395_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_354_395_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_354_395_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;s.top()</span><span style="color: #000000">-&gt;</span><span style="color: #000000">right;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.pop();<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_435_670_Open_Image" onclick="this.style.display='none'; Codehighlighter1_435_670_Open_Text.style.display='none'; Codehighlighter1_435_670_Closed_Image.style.display='inline'; Codehighlighter1_435_670_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_435_670_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_435_670_Closed_Text.style.display='none'; Codehighlighter1_435_670_Open_Image.style.display='inline'; Codehighlighter1_435_670_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;preOrder2(BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">root)</span><span id="Codehighlighter1_435_670_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_435_670_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">先序2</span><span style="color: #008000"><br /></span><span style="color: #008080">26</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;stack</span><span style="color: #000000">&lt;</span><span style="color: #000000">BinTreeNode</span><span style="color: #000000">*&gt;</span><span style="color: #000000">&nbsp;s;<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">tmp</span><span style="color: #000000">=</span><span style="color: #000000">root;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_521_668_Open_Image" onclick="this.style.display='none'; Codehighlighter1_521_668_Open_Text.style.display='none'; Codehighlighter1_521_668_Closed_Image.style.display='inline'; Codehighlighter1_521_668_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_521_668_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_521_668_Closed_Text.style.display='none'; Codehighlighter1_521_668_Open_Image.style.display='inline'; Codehighlighter1_521_668_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_521_668_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_521_668_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img id="Codehighlighter1_541_613_Open_Image" onclick="this.style.display='none'; Codehighlighter1_541_613_Open_Text.style.display='none'; Codehighlighter1_541_613_Closed_Image.style.display='inline'; Codehighlighter1_541_613_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_541_613_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_541_613_Closed_Text.style.display='none'; Codehighlighter1_541_613_Open_Image.style.display='inline'; Codehighlighter1_541_613_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_541_613_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_541_613_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.push(tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">right);<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">left;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">34</span><span style="color: #000000"><img id="Codehighlighter1_631_665_Open_Image" onclick="this.style.display='none'; Codehighlighter1_631_665_Open_Text.style.display='none'; Codehighlighter1_631_665_Closed_Image.style.display='inline'; Codehighlighter1_631_665_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_631_665_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_631_665_Closed_Text.style.display='none'; Codehighlighter1_631_665_Open_Image.style.display='inline'; Codehighlighter1_631_665_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_631_665_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_631_665_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;s.top();<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.pop();<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img id="Codehighlighter1_703_944_Open_Image" onclick="this.style.display='none'; Codehighlighter1_703_944_Open_Text.style.display='none'; Codehighlighter1_703_944_Closed_Image.style.display='inline'; Codehighlighter1_703_944_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_703_944_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_703_944_Closed_Text.style.display='none'; Codehighlighter1_703_944_Open_Image.style.display='inline'; Codehighlighter1_703_944_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;InOrder(BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">root)</span><span id="Codehighlighter1_703_944_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_703_944_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">中序</span><span style="color: #008000"><br /></span><span style="color: #008080">41</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;stack</span><span style="color: #000000">&lt;</span><span style="color: #000000">BinTreeNode</span><span style="color: #000000">*&gt;</span><span style="color: #000000">&nbsp;s;<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BinTreeNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">tmp</span><span style="color: #000000">=</span><span style="color: #000000">root;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img id="Codehighlighter1_788_942_Open_Image" onclick="this.style.display='none'; Codehighlighter1_788_942_Open_Text.style.display='none'; Codehighlighter1_788_942_Closed_Image.style.display='inline'; Codehighlighter1_788_942_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_788_942_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_788_942_Closed_Text.style.display='none'; Codehighlighter1_788_942_Open_Image.style.display='inline'; Codehighlighter1_788_942_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_788_942_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_788_942_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img id="Codehighlighter1_808_851_Open_Image" onclick="this.style.display='none'; Codehighlighter1_808_851_Open_Text.style.display='none'; Codehighlighter1_808_851_Closed_Image.style.display='inline'; Codehighlighter1_808_851_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_808_851_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_808_851_Closed_Text.style.display='none'; Codehighlighter1_808_851_Open_Image.style.display='inline'; Codehighlighter1_808_851_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(tmp</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_808_851_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_808_851_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.push(tmp);<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">left;<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">48</span><span style="color: #000000"><img id="Codehighlighter1_869_939_Open_Image" onclick="this.style.display='none'; Codehighlighter1_869_939_Open_Text.style.display='none'; Codehighlighter1_869_939_Closed_Image.style.display='inline'; Codehighlighter1_869_939_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_869_939_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_869_939_Closed_Text.style.display='none'; Codehighlighter1_869_939_Open_Image.style.display='inline'; Codehighlighter1_869_939_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_869_939_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_869_939_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">s.top()</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;s.top()</span><span style="color: #000000">-&gt;</span><span style="color: #000000">right;<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.pop();<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">53</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">54</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/153724.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-08-18 15:14 <a href="http://www.cppblog.com/dotaqop/articles/153724.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用面向对象语言实现一个计算器控制台程序</title><link>http://www.cppblog.com/dotaqop/articles/153193.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 12 Aug 2011 06:18:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/153193.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/153193.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/153193.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/153193.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/153193.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #008000">//</span><span style="color: #008000">Operation&nbsp;运算类</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #008000"><img id="Codehighlighter1_72_347_Open_Image" onclick="this.style.display='none'; Codehighlighter1_72_347_Open_Text.style.display='none'; Codehighlighter1_72_347_Closed_Image.style.display='inline'; Codehighlighter1_72_347_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_72_347_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_72_347_Closed_Text.style.display='none'; Codehighlighter1_72_347_Open_Image.style.display='inline'; Codehighlighter1_72_347_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Operation</span><span id="Codehighlighter1_72_347_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_72_347_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;m_numberA;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;m_numberB;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img id="Codehighlighter1_147_166_Open_Image" onclick="this.style.display='none'; Codehighlighter1_147_166_Open_Text.style.display='none'; Codehighlighter1_147_166_Closed_Image.style.display='inline'; Codehighlighter1_147_166_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_147_166_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_147_166_Closed_Text.style.display='none'; Codehighlighter1_147_166_Open_Image.style.display='inline'; Codehighlighter1_147_166_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;SetNumA(</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;numA)&nbsp;</span><span id="Codehighlighter1_147_166_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_147_166_Open_Text"><span style="color: #000000">{&nbsp;m_numberA&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;numA;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_195_214_Open_Image" onclick="this.style.display='none'; Codehighlighter1_195_214_Open_Text.style.display='none'; Codehighlighter1_195_214_Closed_Image.style.display='inline'; Codehighlighter1_195_214_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_195_214_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_195_214_Closed_Text.style.display='none'; Codehighlighter1_195_214_Open_Image.style.display='inline'; Codehighlighter1_195_214_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;SetNumB(</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;numB)&nbsp;</span><span id="Codehighlighter1_195_214_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_195_214_Open_Text"><span style="color: #000000">{&nbsp;m_numberB&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;numB;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_244_263_Open_Image" onclick="this.style.display='none'; Codehighlighter1_244_263_Open_Text.style.display='none'; Codehighlighter1_244_263_Closed_Image.style.display='inline'; Codehighlighter1_244_263_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_244_263_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_244_263_Closed_Text.style.display='none'; Codehighlighter1_244_263_Open_Image.style.display='inline'; Codehighlighter1_244_263_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetNumA(</span><span style="color: #0000ff">void</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_244_263_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_244_263_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;m_numberA;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_293_312_Open_Image" onclick="this.style.display='none'; Codehighlighter1_293_312_Open_Text.style.display='none'; Codehighlighter1_293_312_Closed_Image.style.display='inline'; Codehighlighter1_293_312_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_293_312_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_293_312_Closed_Text.style.display='none'; Codehighlighter1_293_312_Open_Image.style.display='inline'; Codehighlighter1_293_312_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetNumB(</span><span style="color: #0000ff">void</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_293_312_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_293_312_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;m_numberB;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetResult()&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_385_451_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_451_Open_Text.style.display='none'; Codehighlighter1_385_451_Closed_Image.style.display='inline'; Codehighlighter1_385_451_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_385_451_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_385_451_Closed_Text.style.display='none'; Codehighlighter1_385_451_Open_Image.style.display='inline'; Codehighlighter1_385_451_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;OperationAdd:</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;Operation</span><span id="Codehighlighter1_385_451_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_385_451_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_414_449_Open_Image" onclick="this.style.display='none'; Codehighlighter1_414_449_Open_Text.style.display='none'; Codehighlighter1_414_449_Closed_Image.style.display='inline'; Codehighlighter1_414_449_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_414_449_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_414_449_Closed_Text.style.display='none'; Codehighlighter1_414_449_Open_Image.style.display='inline'; Codehighlighter1_414_449_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetResult()</span><span id="Codehighlighter1_414_449_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_414_449_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;GetNumA()&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;GetNumB();<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_489_555_Open_Image" onclick="this.style.display='none'; Codehighlighter1_489_555_Open_Text.style.display='none'; Codehighlighter1_489_555_Closed_Image.style.display='inline'; Codehighlighter1_489_555_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_489_555_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_489_555_Closed_Text.style.display='none'; Codehighlighter1_489_555_Open_Image.style.display='inline'; Codehighlighter1_489_555_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;OperationSub:</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;Operation</span><span id="Codehighlighter1_489_555_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_489_555_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_518_553_Open_Image" onclick="this.style.display='none'; Codehighlighter1_518_553_Open_Text.style.display='none'; Codehighlighter1_518_553_Closed_Image.style.display='inline'; Codehighlighter1_518_553_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_518_553_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_518_553_Closed_Text.style.display='none'; Codehighlighter1_518_553_Open_Image.style.display='inline'; Codehighlighter1_518_553_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetResult()</span><span id="Codehighlighter1_518_553_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_518_553_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;GetNumA()&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;GetNumB();<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_593_659_Open_Image" onclick="this.style.display='none'; Codehighlighter1_593_659_Open_Text.style.display='none'; Codehighlighter1_593_659_Closed_Image.style.display='inline'; Codehighlighter1_593_659_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_593_659_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_593_659_Closed_Text.style.display='none'; Codehighlighter1_593_659_Open_Image.style.display='inline'; Codehighlighter1_593_659_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;OperationMul:</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;Operation</span><span id="Codehighlighter1_593_659_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_593_659_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_622_657_Open_Image" onclick="this.style.display='none'; Codehighlighter1_622_657_Open_Text.style.display='none'; Codehighlighter1_622_657_Closed_Image.style.display='inline'; Codehighlighter1_622_657_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_622_657_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_622_657_Closed_Text.style.display='none'; Codehighlighter1_622_657_Open_Image.style.display='inline'; Codehighlighter1_622_657_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetResult()</span><span id="Codehighlighter1_622_657_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_622_657_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;GetNumA()&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;GetNumB();<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img id="Codehighlighter1_697_820_Open_Image" onclick="this.style.display='none'; Codehighlighter1_697_820_Open_Text.style.display='none'; Codehighlighter1_697_820_Closed_Image.style.display='inline'; Codehighlighter1_697_820_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_697_820_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_697_820_Closed_Text.style.display='none'; Codehighlighter1_697_820_Open_Image.style.display='inline'; Codehighlighter1_697_820_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;OperationDiv:</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;Operation</span><span id="Codehighlighter1_697_820_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_697_820_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img id="Codehighlighter1_726_818_Open_Image" onclick="this.style.display='none'; Codehighlighter1_726_818_Open_Text.style.display='none'; Codehighlighter1_726_818_Closed_Image.style.display='inline'; Codehighlighter1_726_818_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_726_818_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_726_818_Closed_Text.style.display='none'; Codehighlighter1_726_818_Open_Image.style.display='inline'; Codehighlighter1_726_818_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;GetResult()</span><span id="Codehighlighter1_726_818_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_726_818_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(GetNumB()&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">throw</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">numB&nbsp;cannot&nbsp;be&nbsp;zero!</span><span style="color: #000000">"</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;GetNumA()&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;GetNumB();<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img id="Codehighlighter1_845_1183_Open_Image" onclick="this.style.display='none'; Codehighlighter1_845_1183_Open_Text.style.display='none'; Codehighlighter1_845_1183_Closed_Image.style.display='inline'; Codehighlighter1_845_1183_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_845_1183_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_845_1183_Closed_Text.style.display='none'; Codehighlighter1_845_1183_Open_Image.style.display='inline'; Codehighlighter1_845_1183_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;OperationFactory</span><span id="Codehighlighter1_845_1183_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_845_1183_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img id="Codehighlighter1_898_1181_Open_Image" onclick="this.style.display='none'; Codehighlighter1_898_1181_Open_Text.style.display='none'; Codehighlighter1_898_1181_Closed_Image.style.display='inline'; Codehighlighter1_898_1181_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_898_1181_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_898_1181_Closed_Text.style.display='none'; Codehighlighter1_898_1181_Open_Image.style.display='inline'; Codehighlighter1_898_1181_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;Operation</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;CreateOperate(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;oper)</span><span id="Codehighlighter1_898_1181_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_898_1181_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Operation&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">poper&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;NULL;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img id="Codehighlighter1_942_1162_Open_Image" onclick="this.style.display='none'; Codehighlighter1_942_1162_Open_Text.style.display='none'; Codehighlighter1_942_1162_Closed_Image.style.display='inline'; Codehighlighter1_942_1162_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_942_1162_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_942_1162_Closed_Text.style.display='none'; Codehighlighter1_942_1162_Open_Image.style.display='inline'; Codehighlighter1_942_1162_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">switch</span><span style="color: #000000">&nbsp;(oper)</span><span id="Codehighlighter1_942_1162_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_942_1162_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">:<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poper&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;OperationAdd;<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">:<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poper&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;OperationSub;<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">*</span><span style="color: #000000">'</span><span style="color: #000000">:<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poper&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;OperationMul;<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">54</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">/</span><span style="color: #000000">'</span><span style="color: #000000">:<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poper&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;OperationDiv;<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">58</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;poper;<br /></span><span style="color: #008080">59</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">60</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">62</span><span style="color: #000000"><img id="Codehighlighter1_1197_1569_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1197_1569_Open_Text.style.display='none'; Codehighlighter1_1197_1569_Closed_Image.style.display='inline'; Codehighlighter1_1197_1569_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_1197_1569_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1197_1569_Closed_Text.style.display='none'; Codehighlighter1_1197_1569_Open_Image.style.display='inline'; Codehighlighter1_1197_1569_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_1197_1569_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1197_1569_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">input&nbsp;A:</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;numA;<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">numA;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">input&nbsp;operator:</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;oper;<br /></span><span style="color: #008080">68</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">oper;<br /></span><span style="color: #008080">69</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">input&nbsp;B:</span><span style="color: #000000">"</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">70</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;numB;<br /></span><span style="color: #008080">71</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">numB;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">72</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Operation&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">poper&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;OperationFactory::CreateOperate(oper);<br /></span><span style="color: #008080">73</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;poper</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetNumA(numA);<br /></span><span style="color: #008080">74</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;poper</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetNumB(numB);<br /></span><span style="color: #008080">75</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">poper</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetNumA()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">oper</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">poper</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetNumB()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;=&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">poper</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetResult()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;&nbsp;<br /></span><span style="color: #008080">76</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">77</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">78</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div> <img src ="http://www.cppblog.com/dotaqop/aggbug/153193.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-08-12 14:18 <a href="http://www.cppblog.com/dotaqop/articles/153193.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>找出两字符串的最大公共字串</title><link>http://www.cppblog.com/dotaqop/articles/148494.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Sat, 11 Jun 2011 08:54:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148494.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148494.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148494.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148494.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148494.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cassert</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_111_606_Open_Image" onclick="this.style.display='none'; Codehighlighter1_111_606_Open_Text.style.display='none'; Codehighlighter1_111_606_Closed_Image.style.display='inline'; Codehighlighter1_111_606_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_111_606_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_111_606_Closed_Text.style.display='none'; Codehighlighter1_111_606_Open_Image.style.display='inline'; Codehighlighter1_111_606_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;GetSameSubstr(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;&nbsp;s1,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;s2)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_111_606_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_111_606_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len1</span><span style="color: #000000">=</span><span style="color: #000000">strlen(s1);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len2</span><span style="color: #000000">=</span><span style="color: #000000">strlen(s2);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxlen</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxpos</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img id="Codehighlighter1_223_492_Open_Image" onclick="this.style.display='none'; Codehighlighter1_223_492_Open_Text.style.display='none'; Codehighlighter1_223_492_Closed_Image.style.display='inline'; Codehighlighter1_223_492_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_223_492_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_223_492_Closed_Text.style.display='none'; Codehighlighter1_223_492_Open_Image.style.display='inline'; Codehighlighter1_223_492_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">len1;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_223_492_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_223_492_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_250_489_Open_Image" onclick="this.style.display='none'; Codehighlighter1_250_489_Open_Text.style.display='none'; Codehighlighter1_250_489_Closed_Image.style.display='inline'; Codehighlighter1_250_489_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_250_489_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_250_489_Closed_Text.style.display='none'; Codehighlighter1_250_489_Open_Image.style.display='inline'; Codehighlighter1_250_489_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;</span><span style="color: #000000">len2;j</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_250_489_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_250_489_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_271_485_Open_Image" onclick="this.style.display='none'; Codehighlighter1_271_485_Open_Text.style.display='none'; Codehighlighter1_271_485_Closed_Image.style.display='inline'; Codehighlighter1_271_485_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_271_485_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_271_485_Closed_Text.style.display='none'; Codehighlighter1_271_485_Open_Image.style.display='inline'; Codehighlighter1_271_485_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(s2[j]</span><span style="color: #000000">==</span><span style="color: #000000">s1[i])</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_271_485_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_271_485_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;index1</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;index2</span><span style="color: #000000">=</span><span style="color: #000000">j;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">注意循环条件</span><span style="color: #008000"><br /><img id="Codehighlighter1_360_380_Open_Image" onclick="this.style.display='none'; Codehighlighter1_360_380_Open_Text.style.display='none'; Codehighlighter1_360_380_Closed_Image.style.display='inline'; Codehighlighter1_360_380_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_360_380_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_360_380_Closed_Text.style.display='none'; Codehighlighter1_360_380_Open_Image.style.display='inline'; Codehighlighter1_360_380_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(index1</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">&lt;</span><span style="color: #000000">len1&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_360_380_Closed_Text">/**/</span><span id="Codehighlighter1_360_380_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&amp;&amp;&nbsp;index2+1&lt;len2&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;s1[</span><span style="color: #000000">++</span><span style="color: #000000">index1]</span><span style="color: #000000">==</span><span style="color: #000000">s2[</span><span style="color: #000000">++</span><span style="color: #000000">index2])<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img id="Codehighlighter1_442_480_Open_Image" onclick="this.style.display='none'; Codehighlighter1_442_480_Open_Text.style.display='none'; Codehighlighter1_442_480_Closed_Image.style.display='inline'; Codehighlighter1_442_480_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_442_480_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_442_480_Closed_Text.style.display='none'; Codehighlighter1_442_480_Open_Image.style.display='inline'; Codehighlighter1_442_480_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(cnt</span><span style="color: #000000">&gt;</span><span style="color: #000000">maxlen)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_442_480_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_442_480_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxlen</span><span style="color: #000000">=</span><span style="color: #000000">cnt;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxpos</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;address</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">[maxlen</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strncpy(address,s1</span><span style="color: #000000">+</span><span style="color: #000000">maxpos,maxlen);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;address[maxlen]</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;address;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_620_778_Open_Image" onclick="this.style.display='none'; Codehighlighter1_620_778_Open_Text.style.display='none'; Codehighlighter1_620_778_Closed_Image.style.display='inline'; Codehighlighter1_620_778_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_620_778_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_620_778_Closed_Text.style.display='none'; Codehighlighter1_620_778_Open_Image.style.display='inline'; Codehighlighter1_620_778_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_620_778_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_620_778_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str1[]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">abc12abc123</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str2[]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">abc123</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">=</span><span style="color: #000000">GetSameSubstr(str1,str2);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">tmp</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;delete[]&nbsp;tmp;</span><span style="color: #008000">//</span><span style="color: #008000">释放内存</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/148494.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-11 16:54 <a href="http://www.cppblog.com/dotaqop/articles/148494.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将10进制数转换成2进制,8进制,16进制输出</title><link>http://www.cppblog.com/dotaqop/articles/148414.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 10 Jun 2011 04:41:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148414.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148414.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148414.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148414.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148414.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;N&nbsp;2</span><span style="color: #008000">//</span><span style="color: #008000">8&nbsp;16</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_71_144_Open_Image" onclick="this.style.display='none'; Codehighlighter1_71_144_Open_Text.style.display='none'; Codehighlighter1_71_144_Closed_Image.style.display='inline'; Codehighlighter1_71_144_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_71_144_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_71_144_Closed_Text.style.display='none'; Codehighlighter1_71_144_Open_Image.style.display='inline'; Codehighlighter1_71_144_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;Node</span><span id="Codehighlighter1_71_144_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_71_144_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;next;<br /><img id="Codehighlighter1_141_142_Open_Image" onclick="this.style.display='none'; Codehighlighter1_141_142_Open_Text.style.display='none'; Codehighlighter1_141_142_Closed_Image.style.display='inline'; Codehighlighter1_141_142_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_141_142_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_141_142_Closed_Text.style.display='none'; Codehighlighter1_141_142_Open_Image.style.display='inline'; Codehighlighter1_141_142_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;Node(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;t</span><span style="color: #000000">=</span><span style="color: #0000ff">int</span><span style="color: #000000">()):data(t),next(NULL)</span><span id="Codehighlighter1_141_142_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_141_142_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;dec2bin(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_182_598_Open_Image" onclick="this.style.display='none'; Codehighlighter1_182_598_Open_Text.style.display='none'; Codehighlighter1_182_598_Closed_Image.style.display='inline'; Codehighlighter1_182_598_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_182_598_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_182_598_Closed_Text.style.display='none'; Codehighlighter1_182_598_Open_Image.style.display='inline'; Codehighlighter1_182_598_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_182_598_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_182_598_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">NULL;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">num;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num2</span><span style="color: #000000">=</span><span style="color: #000000">num;<br /><img id="Codehighlighter1_255_321_Open_Image" onclick="this.style.display='none'; Codehighlighter1_255_321_Open_Text.style.display='none'; Codehighlighter1_255_321_Closed_Image.style.display='inline'; Codehighlighter1_255_321_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_255_321_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_255_321_Closed_Text.style.display='none'; Codehighlighter1_255_321_Open_Image.style.display='inline'; Codehighlighter1_255_321_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(num</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span id="Codehighlighter1_255_321_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_255_321_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Node(num</span><span style="color: #000000">%</span><span style="color: #000000">N);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">p;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="color: #000000">/=</span><span style="color: #000000">N;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;Node&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">q</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img id="Codehighlighter1_353_442_Open_Image" onclick="this.style.display='none'; Codehighlighter1_353_442_Open_Text.style.display='none'; Codehighlighter1_353_442_Closed_Image.style.display='inline'; Codehighlighter1_353_442_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_353_442_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_353_442_Closed_Text.style.display='none'; Codehighlighter1_353_442_Open_Image.style.display='inline'; Codehighlighter1_353_442_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(q</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_353_442_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_353_442_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;</span><span style="color: #000000">10</span><span style="color: #000000">)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #0000ff">char</span><span style="color: #000000">(q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">-</span><span style="color: #000000">10</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">a</span><span style="color: #000000">'</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img id="Codehighlighter1_475_519_Open_Image" onclick="this.style.display='none'; Codehighlighter1_475_519_Open_Text.style.display='none'; Codehighlighter1_475_519_Closed_Image.style.display='inline'; Codehighlighter1_475_519_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_475_519_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_475_519_Closed_Text.style.display='none'; Codehighlighter1_475_519_Open_Image.style.display='inline'; Codehighlighter1_475_519_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(head</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_475_519_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_475_519_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;head;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">q;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">---------------</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;dec2bin(num2);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_600_628_Open_Image" style="display: inline" onclick="this.style.display='none'; Codehighlighter1_600_628_Open_Text.style.display='none'; Codehighlighter1_600_628_Closed_Image.style.display='inline'; Codehighlighter1_600_628_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_600_628_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_600_628_Closed_Text.style.display='none'; Codehighlighter1_600_628_Open_Image.style.display='inline'; Codehighlighter1_600_628_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_600_628_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_600_628_Open_Text" style="display: inline"><span style="color: #808080">///////////////////////<br /></span></span><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000">//</span><span style="color: #008000">10-&gt;2进制&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位运算方法</span><span style="color: #008000">//<br /><img id="Codehighlighter1_651_679_Open_Image" onclick="this.style.display='none'; Codehighlighter1_651_679_Open_Text.style.display='none'; Codehighlighter1_651_679_Closed_Image.style.display='inline'; Codehighlighter1_651_679_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_651_679_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_651_679_Closed_Text.style.display='none'; Codehighlighter1_651_679_Open_Image.style.display='inline'; Codehighlighter1_651_679_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_651_679_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_651_679_Open_Text"><span style="color: #808080">///////////////////////</span></span><br /><img id="Codehighlighter1_701_836_Open_Image" onclick="this.style.display='none'; Codehighlighter1_701_836_Open_Text.style.display='none'; Codehighlighter1_701_836_Closed_Image.style.display='inline'; Codehighlighter1_701_836_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_701_836_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_701_836_Closed_Text.style.display='none'; Codehighlighter1_701_836_Open_Image.style.display='inline'; Codehighlighter1_701_836_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;dec2bin(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num)</span><span id="Codehighlighter1_701_836_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_701_836_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;intbitlen&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)</span><span style="color: #000000">*</span><span style="color: #000000">8</span><span style="color: #000000">;<br /><img id="Codehighlighter1_767_821_Open_Image" onclick="this.style.display='none'; Codehighlighter1_767_821_Open_Text.style.display='none'; Codehighlighter1_767_821_Closed_Image.style.display='inline'; Codehighlighter1_767_821_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_767_821_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_767_821_Closed_Text.style.display='none'; Codehighlighter1_767_821_Open_Image.style.display='inline'; Codehighlighter1_767_821_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">intbitlen</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">--</span><span style="color: #000000">)</span><span id="Codehighlighter1_767_821_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_767_821_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">((</span><span style="color: #000000">1</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">i)</span><span style="color: #000000">&amp;</span><span style="color: #000000">num)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">1</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/148414.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-10 12:41 <a href="http://www.cppblog.com/dotaqop/articles/148414.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将16进制字符串转换成10进制数</title><link>http://www.cppblog.com/dotaqop/articles/148412.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 10 Jun 2011 04:22:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148412.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148412.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148412.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148412.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148412.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<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"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cassert</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #008000">//<br /><img id="Codehighlighter1_112_482_Open_Image" onclick="this.style.display='none'; Codehighlighter1_112_482_Open_Text.style.display='none'; Codehighlighter1_112_482_Closed_Image.style.display='inline'; Codehighlighter1_112_482_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_112_482_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_112_482_Closed_Text.style.display='none'; Codehighlighter1_112_482_Open_Image.style.display='inline'; Codehighlighter1_112_482_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;hexstr2dec(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;str)</span><span id="Codehighlighter1_112_482_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_112_482_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;result</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;decnum</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len</span><span style="color: #000000">=</span><span style="color: #000000">strlen(str);<br /><img id="Codehighlighter1_189_464_Open_Image" onclick="this.style.display='none'; Codehighlighter1_189_464_Open_Text.style.display='none'; Codehighlighter1_189_464_Closed_Image.style.display='inline'; Codehighlighter1_189_464_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_189_464_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_189_464_Closed_Text.style.display='none'; Codehighlighter1_189_464_Open_Image.style.display='inline'; Codehighlighter1_189_464_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">len;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span id="Codehighlighter1_189_464_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_189_464_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(str[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">9</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">str[i]</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decnum</span><span style="color: #000000">=</span><span style="color: #000000">str[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(str[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">f</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">str[i]</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">a</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decnum</span><span style="color: #000000">=</span><span style="color: #000000">str[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">a</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(str[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">F</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">str[i]</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decnum</span><span style="color: #000000">=</span><span style="color: #000000">str[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img id="Codehighlighter1_372_418_Open_Image" onclick="this.style.display='none'; Codehighlighter1_372_418_Open_Text.style.display='none'; Codehighlighter1_372_418_Closed_Image.style.display='inline'; Codehighlighter1_372_418_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_372_418_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_372_418_Closed_Text.style.display='none'; Codehighlighter1_372_418_Open_Image.style.display='inline'; Codehighlighter1_372_418_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span id="Codehighlighter1_372_418_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_372_418_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">十六进制字符串不对</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decnum</span><span style="color: #000000">&lt;&lt;=</span><span style="color: #000000">(len</span><span style="color: #000000">-</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">2</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result</span><span style="color: #000000">+=</span><span style="color: #000000">decnum;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;result;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_496_614_Open_Image" onclick="this.style.display='none'; Codehighlighter1_496_614_Open_Text.style.display='none'; Codehighlighter1_496_614_Closed_Image.style.display='inline'; Codehighlighter1_496_614_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_496_614_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_496_614_Closed_Text.style.display='none'; Codehighlighter1_496_614_Open_Image.style.display='inline'; Codehighlighter1_496_614_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_496_614_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_496_614_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;str;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">str;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">hexstr2dec(str.c_str())</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;</span><span style="color: #008000">//</span><span style="color: #008000">str.c_str()为const&nbsp;char*</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div> <img src ="http://www.cppblog.com/dotaqop/aggbug/148412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-10 12:22 <a href="http://www.cppblog.com/dotaqop/articles/148412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>给出年月日,算出这是一年中的第几天</title><link>http://www.cppblog.com/dotaqop/articles/148298.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Wed, 08 Jun 2011 13:52:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148298.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148298.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148298.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148298.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148298.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_52_399_Open_Image" onclick="this.style.display='none'; Codehighlighter1_52_399_Open_Text.style.display='none'; Codehighlighter1_52_399_Closed_Image.style.display='inline'; Codehighlighter1_52_399_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_52_399_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_52_399_Closed_Text.style.display='none'; Codehighlighter1_52_399_Open_Image.style.display='inline'; Codehighlighter1_52_399_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_52_399_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_52_399_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;year,month,day;<br /><img id="Codehighlighter1_86_123_Open_Image" onclick="this.style.display='none'; Codehighlighter1_86_123_Open_Text.style.display='none'; Codehighlighter1_86_123_Closed_Image.style.display='inline'; Codehighlighter1_86_123_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_86_123_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_86_123_Closed_Text.style.display='none'; Codehighlighter1_86_123_Open_Image.style.display='inline'; Codehighlighter1_86_123_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m[</span><span style="color: #000000">12</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_86_123_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_86_123_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">28</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">30</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">30</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">30</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">30</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">请输入年月日：</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">year</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">month</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">day;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(year</span><span style="color: #000000">%</span><span style="color: #000000">400</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;year</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;year</span><span style="color: #000000">%</span><span style="color: #000000">100</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m[</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">29</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;sumdays</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img id="Codehighlighter1_267_287_Open_Image" onclick="this.style.display='none'; Codehighlighter1_267_287_Open_Text.style.display='none'; Codehighlighter1_267_287_Closed_Image.style.display='inline'; Codehighlighter1_267_287_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_267_287_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_267_287_Closed_Text.style.display='none'; Codehighlighter1_267_287_Open_Image.style.display='inline'; Codehighlighter1_267_287_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">month</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_267_287_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_267_287_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sumdays</span><span style="color: #000000">+=</span><span style="color: #000000">m[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sumdays</span><span style="color: #000000">+=</span><span style="color: #000000">day;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">year</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">年</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">month</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">月</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">day</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">日是一年中的第</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">sumdays</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">天</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/148298.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-08 21:52 <a href="http://www.cppblog.com/dotaqop/articles/148298.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>判断数组是否递增</title><link>http://www.cppblog.com/dotaqop/articles/148288.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Wed, 08 Jun 2011 11:04:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148288.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148288.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148288.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148288.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148288.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">优化前的递归</span><span style="color: #008000"><br /><img id="Codehighlighter1_80_180_Open_Image" onclick="this.style.display='none'; Codehighlighter1_80_180_Open_Text.style.display='none'; Codehighlighter1_80_180_Closed_Image.style.display='inline'; Codehighlighter1_80_180_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_80_180_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_80_180_Closed_Text.style.display='none'; Codehighlighter1_80_180_Open_Image.style.display='inline'; Codehighlighter1_80_180_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;IsIncrement(</span><span style="color: #0000ff">int</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;a,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n)</span><span id="Codehighlighter1_80_180_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_80_180_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(n</span><span style="color: #000000">&lt;=</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /><img id="Codehighlighter1_122_156_Open_Image" onclick="this.style.display='none'; Codehighlighter1_122_156_Open_Text.style.display='none'; Codehighlighter1_122_156_Closed_Image.style.display='inline'; Codehighlighter1_122_156_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_122_156_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_122_156_Closed_Text.style.display='none'; Codehighlighter1_122_156_Open_Image.style.display='inline'; Codehighlighter1_122_156_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">a[</span><span style="color: #000000">1</span><span style="color: #000000">])</span><span id="Codehighlighter1_122_156_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_122_156_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #000000">IsIncrement(a</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">,n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">优化后的递归</span><span style="color: #008000"><br /><img id="Codehighlighter1_219_277_Open_Image" onclick="this.style.display='none'; Codehighlighter1_219_277_Open_Text.style.display='none'; Codehighlighter1_219_277_Closed_Image.style.display='inline'; Codehighlighter1_219_277_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_219_277_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_219_277_Closed_Text.style.display='none'; Codehighlighter1_219_277_Open_Image.style.display='inline'; Codehighlighter1_219_277_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;IsBigger(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n)</span><span id="Codehighlighter1_219_277_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_219_277_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">(n</span><span style="color: #000000">&lt;=</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">a[</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;IsBigger(a</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">,n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">));</span><span style="color: #008000">//</span><span style="color: #008000">从前往后</span><span style="color: #008000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="color: #000000">}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_303_360_Open_Image" onclick="this.style.display='none'; Codehighlighter1_303_360_Open_Text.style.display='none'; Codehighlighter1_303_360_Closed_Image.style.display='inline'; Codehighlighter1_303_360_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_303_360_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_303_360_Closed_Text.style.display='none'; Codehighlighter1_303_360_Open_Image.style.display='inline'; Codehighlighter1_303_360_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;IsBig(</span><span style="color: #0000ff">int</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;a,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n)</span><span id="Codehighlighter1_303_360_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_303_360_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">(n</span><span style="color: #000000">&lt;=</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;a[n</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">a[n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;IsBig(a,n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">));</span><span style="color: #008000">//</span><span style="color: #008000">从后往前</span><span style="color: #008000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="color: #000000">}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">非递归的</span><span style="color: #008000"><br /><img id="Codehighlighter1_398_474_Open_Image" onclick="this.style.display='none'; Codehighlighter1_398_474_Open_Text.style.display='none'; Codehighlighter1_398_474_Closed_Image.style.display='inline'; Codehighlighter1_398_474_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_398_474_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_398_474_Closed_Text.style.display='none'; Codehighlighter1_398_474_Open_Image.style.display='inline'; Codehighlighter1_398_474_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;Increment(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n)</span><span id="Codehighlighter1_398_474_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_398_474_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[i]</span><span style="color: #000000">&lt;</span><span style="color: #000000">a[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">])<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;&nbsp;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">&nbsp;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_488_572_Open_Image" onclick="this.style.display='none'; Codehighlighter1_488_572_Open_Text.style.display='none'; Codehighlighter1_488_572_Closed_Image.style.display='inline'; Codehighlighter1_488_572_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_488_572_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_488_572_Closed_Text.style.display='none'; Codehighlighter1_488_572_Open_Image.style.display='inline'; Codehighlighter1_488_572_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_488_572_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_488_572_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_500_510_Open_Image" onclick="this.style.display='none'; Codehighlighter1_500_510_Open_Text.style.display='none'; Codehighlighter1_500_510_Closed_Image.style.display='inline'; Codehighlighter1_500_510_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_500_510_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_500_510_Closed_Text.style.display='none'; Codehighlighter1_500_510_Open_Image.style.display='inline'; Codehighlighter1_500_510_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">5</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span id="Codehighlighter1_500_510_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_500_510_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">2</span><span style="color: #000000">,</span><span style="color: #000000">3</span><span style="color: #000000">,</span><span style="color: #000000">4</span><span style="color: #000000">,</span><span style="color: #000000">5</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">boolalpha</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">IsBig(a,</span><span style="color: #000000">5</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div>
<p>&nbsp;</p><img src ="http://www.cppblog.com/dotaqop/aggbug/148288.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-08 19:04 <a href="http://www.cppblog.com/dotaqop/articles/148288.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>找出倒数第k个元素(或中间元素）</title><link>http://www.cppblog.com/dotaqop/articles/148244.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Wed, 08 Jun 2011 01:56:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148244.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148244.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148244.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148244.html</trackback:ping><description><![CDATA[<div>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<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"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">list</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;LIST_LENGTH</span><span style="color: #000000">=</span><span style="color: #000000">100</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />typedef&nbsp;list</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;LI;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />typedef&nbsp;list</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">::const_iterator&nbsp;LI_C_IT;</span><span style="color: #008000">//</span><span style="color: #008000">指向常量的指针<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #008000">//</span><span style="color: #008000">找出倒数第k个元素(或中间元素）</span><span style="color: #008000"><br /><img id="Codehighlighter1_215_389_Open_Image" onclick="this.style.display='none'; Codehighlighter1_215_389_Open_Text.style.display='none'; Codehighlighter1_215_389_Closed_Image.style.display='inline'; Codehighlighter1_215_389_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_215_389_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_215_389_Closed_Text.style.display='none'; Codehighlighter1_215_389_Open_Image.style.display='inline'; Codehighlighter1_215_389_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;GetElement(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;LI</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;head,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k)</span><span id="Codehighlighter1_215_389_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_215_389_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(k</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">&gt;</span><span style="color: #000000">LIST_LENGTH)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;LI_C_IT&nbsp;itA,itB;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;itA</span><span style="color: #000000">=</span><span style="color: #000000">itB</span><span style="color: #000000">=</span><span style="color: #000000">head.begin();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">k;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itB</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img id="Codehighlighter1_352_373_Open_Image" onclick="this.style.display='none'; Codehighlighter1_352_373_Open_Text.style.display='none'; Codehighlighter1_352_373_Closed_Image.style.display='inline'; Codehighlighter1_352_373_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_352_373_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_352_373_Closed_Text.style.display='none'; Codehighlighter1_352_373_Open_Image.style.display='inline'; Codehighlighter1_352_373_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(itB&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;head.end())</span><span id="Codehighlighter1_352_373_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_352_373_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itA</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itB</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">itA;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_403_674_Open_Image" onclick="this.style.display='none'; Codehighlighter1_403_674_Open_Text.style.display='none'; Codehighlighter1_403_674_Closed_Image.style.display='inline'; Codehighlighter1_403_674_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_403_674_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_403_674_Closed_Text.style.display='none'; Codehighlighter1_403_674_Open_Image.style.display='inline'; Codehighlighter1_403_674_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_403_674_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_403_674_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;LI&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">创建链表1-&gt;2-&gt;<img src="http://www.cppblog.com/Images/dot.gif"  alt="" />-&gt;100</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">LIST_LENGTH;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head.push_back(i);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k;<br /><img id="Codehighlighter1_513_661_Open_Image" onclick="this.style.display='none'; Codehighlighter1_513_661_Open_Text.style.display='none'; Codehighlighter1_513_661_Closed_Image.style.display='inline'; Codehighlighter1_513_661_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_513_661_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_513_661_Closed_Text.style.display='none'; Codehighlighter1_513_661_Open_Image.style.display='inline'; Codehighlighter1_513_661_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">k)</span><span id="Codehighlighter1_513_661_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_513_661_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">当输入非整数时,如a,b,c<img src="http://www.cppblog.com/Images/dot.gif"  alt="" />就会结束while</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;elem</span><span style="color: #000000">=</span><span style="color: #000000">GetElement(head,k);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(elem</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">无效的测试数据</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">倒数第</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">k</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">个元素是</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">elem</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div></div><img src ="http://www.cppblog.com/dotaqop/aggbug/148244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-08 09:56 <a href="http://www.cppblog.com/dotaqop/articles/148244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>删除链表中数据为DATA的所有节点（无头节点） </title><link>http://www.cppblog.com/dotaqop/articles/148217.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Tue, 07 Jun 2011 09:10:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148217.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148217.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148217.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148217.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148217.html</trackback:ping><description><![CDATA[<div>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<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"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img id="Codehighlighter1_52_125_Open_Image" onclick="this.style.display='none'; Codehighlighter1_52_125_Open_Text.style.display='none'; Codehighlighter1_52_125_Closed_Image.style.display='inline'; Codehighlighter1_52_125_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_52_125_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_52_125_Closed_Text.style.display='none'; Codehighlighter1_52_125_Open_Image.style.display='inline'; Codehighlighter1_52_125_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;Node</span><span id="Codehighlighter1_52_125_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_52_125_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;next;<br /><img id="Codehighlighter1_122_123_Open_Image" onclick="this.style.display='none'; Codehighlighter1_122_123_Open_Text.style.display='none'; Codehighlighter1_122_123_Closed_Image.style.display='inline'; Codehighlighter1_122_123_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_122_123_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_122_123_Closed_Text.style.display='none'; Codehighlighter1_122_123_Open_Image.style.display='inline'; Codehighlighter1_122_123_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;Node(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;t</span><span style="color: #000000">=</span><span style="color: #0000ff">int</span><span style="color: #000000">()):data(t),next(NULL)</span><span id="Codehighlighter1_122_123_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_122_123_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /><img id="Codehighlighter1_163_512_Open_Image" onclick="this.style.display='none'; Codehighlighter1_163_512_Open_Text.style.display='none'; Codehighlighter1_163_512_Closed_Image.style.display='inline'; Codehighlighter1_163_512_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_163_512_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_163_512_Closed_Text.style.display='none'; Codehighlighter1_163_512_Open_Image.style.display='inline'; Codehighlighter1_163_512_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top">Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;del_node(Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;head,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;DATA)</span><span id="Codehighlighter1_163_512_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_163_512_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(head</span><span style="color: #000000">==</span><span style="color: #000000">NULL)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;head;<br /><img id="Codehighlighter1_226_278_Open_Image" onclick="this.style.display='none'; Codehighlighter1_226_278_Open_Text.style.display='none'; Codehighlighter1_226_278_Closed_Image.style.display='inline'; Codehighlighter1_226_278_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_226_278_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_226_278_Closed_Text.style.display='none'; Codehighlighter1_226_278_Open_Image.style.display='inline'; Codehighlighter1_226_278_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(head</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">==</span><span style="color: #000000">DATA)</span><span id="Codehighlighter1_226_278_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_226_278_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;hp</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">hp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(head</span><span style="color: #000000">==</span><span style="color: #000000">NULL)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img id="Codehighlighter1_363_496_Open_Image" onclick="this.style.display='none'; Codehighlighter1_363_496_Open_Text.style.display='none'; Codehighlighter1_363_496_Closed_Image.style.display='inline'; Codehighlighter1_363_496_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_363_496_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_363_496_Closed_Text.style.display='none'; Codehighlighter1_363_496_Open_Image.style.display='inline'; Codehighlighter1_363_496_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(q</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_363_496_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_363_496_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_384_416_Open_Image" onclick="this.style.display='none'; Codehighlighter1_384_416_Open_Text.style.display='none'; Codehighlighter1_384_416_Closed_Image.style.display='inline'; Codehighlighter1_384_416_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_384_416_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_384_416_Closed_Text.style.display='none'; Codehighlighter1_384_416_Open_Image.style.display='inline'; Codehighlighter1_384_416_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">!=</span><span style="color: #000000">DATA)</span><span id="Codehighlighter1_384_416_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_384_416_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_424_493_Open_Image" onclick="this.style.display='none'; Codehighlighter1_424_493_Open_Text.style.display='none'; Codehighlighter1_424_493_Closed_Image.style.display='inline'; Codehighlighter1_424_493_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_424_493_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_424_493_Closed_Text.style.display='none'; Codehighlighter1_424_493_Open_Image.style.display='inline'; Codehighlighter1_424_493_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span id="Codehighlighter1_424_493_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_424_493_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">=</span><span style="color: #000000">q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_526_1060_Open_Image" onclick="this.style.display='none'; Codehighlighter1_526_1060_Open_Text.style.display='none'; Codehighlighter1_526_1060_Closed_Image.style.display='inline'; Codehighlighter1_526_1060_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_526_1060_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_526_1060_Closed_Text.style.display='none'; Codehighlighter1_526_1060_Open_Image.style.display='inline'; Codehighlighter1_526_1060_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_526_1060_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_526_1060_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">请输入来建立链表：</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img id="Codehighlighter1_579_660_Open_Image" onclick="this.style.display='none'; Codehighlighter1_579_660_Open_Text.style.display='none'; Codehighlighter1_579_660_Closed_Image.style.display='inline'; Codehighlighter1_579_660_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_579_660_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_579_660_Closed_Text.style.display='none'; Codehighlighter1_579_660_Open_Image.style.display='inline'; Codehighlighter1_579_660_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">do</span><span id="Codehighlighter1_579_660_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_579_660_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">建立一个&lt;无头结点&gt;的链表</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Node(tmp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">p;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #0000ff">while</span><span style="color: #000000">(cin.</span><span style="color: #0000ff">get</span><span style="color: #000000">()</span><span style="color: #000000">!=</span><span style="color: #000000">'</span><span style="color: #000000">\n</span><span style="color: #000000">'</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">建立的链表如下：</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img id="Codehighlighter1_741_779_Open_Image" onclick="this.style.display='none'; Codehighlighter1_741_779_Open_Text.style.display='none'; Codehighlighter1_741_779_Closed_Image.style.display='inline'; Codehighlighter1_741_779_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_741_779_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_741_779_Closed_Text.style.display='none'; Codehighlighter1_741_779_Open_Image.style.display='inline'; Codehighlighter1_741_779_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(p</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_741_779_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_741_779_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">请输入要删除的节点：</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">del_node(head,x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">删除后的链表如下：</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img id="Codehighlighter1_906_944_Open_Image" onclick="this.style.display='none'; Codehighlighter1_906_944_Open_Text.style.display='none'; Codehighlighter1_906_944_Closed_Image.style.display='inline'; Codehighlighter1_906_944_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_906_944_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_906_944_Closed_Text.style.display='none'; Codehighlighter1_906_944_Open_Image.style.display='inline'; Codehighlighter1_906_944_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(p</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_906_944_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_906_944_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img id="Codehighlighter1_984_1029_Open_Image" onclick="this.style.display='none'; Codehighlighter1_984_1029_Open_Text.style.display='none'; Codehighlighter1_984_1029_Closed_Image.style.display='inline'; Codehighlighter1_984_1029_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_984_1029_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_984_1029_Closed_Text.style.display='none'; Codehighlighter1_984_1029_Open_Image.style.display='inline'; Codehighlighter1_984_1029_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(p</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_984_1029_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_984_1029_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">p;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div></div> <img src ="http://www.cppblog.com/dotaqop/aggbug/148217.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-07 17:10 <a href="http://www.cppblog.com/dotaqop/articles/148217.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>删除链表中数据为DATA的所有节点（有头节点）</title><link>http://www.cppblog.com/dotaqop/articles/148216.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Tue, 07 Jun 2011 09:07:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148216.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148216.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148216.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148216.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148216.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<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"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img id="Codehighlighter1_52_125_Open_Image" onclick="this.style.display='none'; Codehighlighter1_52_125_Open_Text.style.display='none'; Codehighlighter1_52_125_Closed_Image.style.display='inline'; Codehighlighter1_52_125_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_52_125_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_52_125_Closed_Text.style.display='none'; Codehighlighter1_52_125_Open_Image.style.display='inline'; Codehighlighter1_52_125_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;Node</span><span id="Codehighlighter1_52_125_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_52_125_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;next;<br /><img id="Codehighlighter1_122_123_Open_Image" onclick="this.style.display='none'; Codehighlighter1_122_123_Open_Text.style.display='none'; Codehighlighter1_122_123_Closed_Image.style.display='inline'; Codehighlighter1_122_123_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_122_123_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_122_123_Closed_Text.style.display='none'; Codehighlighter1_122_123_Open_Image.style.display='inline'; Codehighlighter1_122_123_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;Node(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;t</span><span style="color: #000000">=</span><span style="color: #0000ff">int</span><span style="color: #000000">()):data(t),next(NULL)</span><span id="Codehighlighter1_122_123_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_122_123_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /><img id="Codehighlighter1_163_378_Open_Image" onclick="this.style.display='none'; Codehighlighter1_163_378_Open_Text.style.display='none'; Codehighlighter1_163_378_Closed_Image.style.display='inline'; Codehighlighter1_163_378_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_163_378_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_163_378_Closed_Text.style.display='none'; Codehighlighter1_163_378_Open_Image.style.display='inline'; Codehighlighter1_163_378_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top">Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;del_node(Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;head,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;DATA)</span><span id="Codehighlighter1_163_378_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_163_378_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img id="Codehighlighter1_216_362_Open_Image" onclick="this.style.display='none'; Codehighlighter1_216_362_Open_Text.style.display='none'; Codehighlighter1_216_362_Closed_Image.style.display='inline'; Codehighlighter1_216_362_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_216_362_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_216_362_Closed_Text.style.display='none'; Codehighlighter1_216_362_Open_Image.style.display='inline'; Codehighlighter1_216_362_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(q</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_216_362_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_216_362_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_237_269_Open_Image" onclick="this.style.display='none'; Codehighlighter1_237_269_Open_Text.style.display='none'; Codehighlighter1_237_269_Closed_Image.style.display='inline'; Codehighlighter1_237_269_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_237_269_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_237_269_Closed_Text.style.display='none'; Codehighlighter1_237_269_Open_Image.style.display='inline'; Codehighlighter1_237_269_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">!=</span><span style="color: #000000">DATA)</span><span id="Codehighlighter1_237_269_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_237_269_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_277_359_Open_Image" onclick="this.style.display='none'; Codehighlighter1_277_359_Open_Text.style.display='none'; Codehighlighter1_277_359_Closed_Image.style.display='inline'; Codehighlighter1_277_359_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_277_359_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_277_359_Closed_Text.style.display='none'; Codehighlighter1_277_359_Open_Image.style.display='inline'; Codehighlighter1_277_359_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span id="Codehighlighter1_277_359_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_277_359_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;tmp</span><span style="color: #000000">=</span><span style="color: #000000">q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">q</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">break;&nbsp;</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_392_949_Open_Image" onclick="this.style.display='none'; Codehighlighter1_392_949_Open_Text.style.display='none'; Codehighlighter1_392_949_Closed_Image.style.display='inline'; Codehighlighter1_392_949_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_392_949_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_392_949_Closed_Text.style.display='none'; Codehighlighter1_392_949_Open_Image.style.display='inline'; Codehighlighter1_392_949_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_392_949_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_392_949_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">请输入来建立链表：</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img id="Codehighlighter1_445_534_Open_Image" onclick="this.style.display='none'; Codehighlighter1_445_534_Open_Text.style.display='none'; Codehighlighter1_445_534_Closed_Image.style.display='inline'; Codehighlighter1_445_534_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_445_534_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_445_534_Closed_Text.style.display='none'; Codehighlighter1_445_534_Open_Image.style.display='inline'; Codehighlighter1_445_534_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">do</span><span id="Codehighlighter1_445_534_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_445_534_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">建立一个&lt;有头结点&gt;的链表,空表就do一次</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Node(tmp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">p;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #0000ff">while</span><span style="color: #000000">(cin.</span><span style="color: #0000ff">get</span><span style="color: #000000">()</span><span style="color: #000000">!=</span><span style="color: #000000">'</span><span style="color: #000000">\n</span><span style="color: #000000">'</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">建立的链表如下：</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Node</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img id="Codehighlighter1_621_659_Open_Image" onclick="this.style.display='none'; Codehighlighter1_621_659_Open_Text.style.display='none'; Codehighlighter1_621_659_Closed_Image.style.display='inline'; Codehighlighter1_621_659_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_621_659_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_621_659_Closed_Text.style.display='none'; Codehighlighter1_621_659_Open_Image.style.display='inline'; Codehighlighter1_621_659_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(p</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_621_659_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_621_659_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">请输入要删除的节点：</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">del_node(head,x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">删除后的链表如下：</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img id="Codehighlighter1_792_830_Open_Image" onclick="this.style.display='none'; Codehighlighter1_792_830_Open_Text.style.display='none'; Codehighlighter1_792_830_Closed_Image.style.display='inline'; Codehighlighter1_792_830_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_792_830_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_792_830_Closed_Text.style.display='none'; Codehighlighter1_792_830_Open_Image.style.display='inline'; Codehighlighter1_792_830_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(p</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_792_830_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_792_830_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">data</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head;<br /><img id="Codehighlighter1_870_914_Open_Image" onclick="this.style.display='none'; Codehighlighter1_870_914_Open_Text.style.display='none'; Codehighlighter1_870_914_Closed_Image.style.display='inline'; Codehighlighter1_870_914_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_870_914_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_870_914_Closed_Text.style.display='none'; Codehighlighter1_870_914_Open_Image.style.display='inline'; Codehighlighter1_870_914_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(p</span><span style="color: #000000">!=</span><span style="color: #000000">NULL)</span><span id="Codehighlighter1_870_914_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_870_914_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">head</span><span style="color: #000000">-&gt;</span><span style="color: #000000">next;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;head;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="color: #000000">=</span><span style="color: #000000">p;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause&gt;nul</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div>    <img src ="http://www.cppblog.com/dotaqop/aggbug/148216.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-07 17:07 <a href="http://www.cppblog.com/dotaqop/articles/148216.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>两个数相乘，小数点后位数没有限制，请写一个高精度算法【转】</title><link>http://www.cppblog.com/dotaqop/articles/148190.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Tue, 07 Jun 2011 02:25:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148190.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148190.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148190.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148190.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148190.html</trackback:ping><description><![CDATA[<p><font face="Verdana" color="#000000">算法提示： </font></p>
<p><font face="Verdana" color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 输入 string a, string b； 计算string c=a*b; 返回 c; </font></p>
<p><font face="Verdana" color="#000000">1，&nbsp;&nbsp;&nbsp; 纪录小数点在a,b中的位置l1,l2， 则需要小数点后移动位置数为l=length(a)+length(b)-l1-l2-2; </font></p>
<p><font face="Verdana" color="#000000">2，&nbsp;&nbsp;&nbsp; 去掉a,b中的小数点，（a,b小数点后移，使a,b变为整数） </font></p>
<p><font face="Verdana" color="#000000">3，&nbsp;&nbsp;&nbsp; 计算c=a*b; （同整数的大数相乘算法） </font></p>
<p><font face="Verdana" color="#000000">4，&nbsp;&nbsp;&nbsp; 输出c,（注意在输出倒数第l个数时，输出一个小数点。若是输出的数少于l个，就补0） </font></p>
<p><font face="Verdana" color="#000000">du51(郁郁思扬)的答案： </font></p><font face="Verdana" color="#000000">
<p><br />变为整数求就行了.输入的时候记一下,小数点位置..输出再做点文章就行了.<br />下面的是大整数的运算.<br />#include&lt;iostream&gt; <br />using namespace std; <br />#define MAX 10000 <br />struct Node{ <br />&nbsp;&nbsp; int data; <br />&nbsp;&nbsp; Node *next; <br />}; <br />void output(Node *head) <br />{ <br />&nbsp;&nbsp; if(!head-&gt;next&amp;&amp;!head-&gt;data)return; <br />&nbsp;&nbsp; output(head-&gt;next); <br />&nbsp;&nbsp; cout&lt;&lt;head-&gt;data; <br />} <br />void Mul(char *a,char *b,int pos)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />{ <br />&nbsp;&nbsp; char *ap=a,*bp=b; <br />&nbsp;&nbsp; Node *head=0; <br />&nbsp;&nbsp; head=new Node;head-&gt;data=0,head-&gt;next=0;&nbsp;&nbsp; //头 <br />&nbsp;&nbsp; Node *p,*q=head,*p1; <br />&nbsp;&nbsp; int temp=0,temp1,bbit; <br />&nbsp;&nbsp; while(*bp)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //若乘数不为空 ,继续. <br />&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=q-&gt;next;p1=q; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bbit=*bp-48;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //把当前位转为整型 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(*ap||temp)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //若被乘数不空,继续 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!p)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //若要操作的结点为空,申请之 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=new Node; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p-&gt;data=0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p-&gt;next=0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1-&gt;next=p; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(*ap==0)temp1=temp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else { temp1=(p1-&gt;data)+(*ap-48)*bbit+temp;ap++; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1-&gt;data=temp1%10;&nbsp;&nbsp;&nbsp; //留当前位 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp=temp1/10;&nbsp;&nbsp;&nbsp; //进位以int的形式留下. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1=p;p=p-&gt;next;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //被乘数到下一位 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ap=a;bp++;q=q-&gt;next;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //q进下一位 <br />&nbsp;&nbsp; } <br />&nbsp;&nbsp; p=head; <br />&nbsp;&nbsp; output(p);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //显示 <br />&nbsp;&nbsp; cout&lt;&lt;endl; <br />&nbsp;&nbsp; while(head)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //释放空间 <br />&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=head-&gt;next; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete head; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; head=p; <br />&nbsp;&nbsp; } <br />} <br />int main() <br />{ <br />&nbsp;&nbsp; cout&lt;&lt;"请输入两个数"&lt;&lt;endl; <br />&nbsp;&nbsp; char test1[MAX],test2[MAX]; <br />&nbsp;&nbsp; cin.getline(test1,MAX,'\n'); <br />&nbsp;&nbsp; cin.getline(test2,MAX,'\n'); <br />&nbsp;&nbsp; Mul(strrev(test1),strrev(test2)); <br />&nbsp;&nbsp; system("PAUSE"); <br />&nbsp;&nbsp; return 0; <br />} <br />上面大整数已经写了.你加几个东西就行了.<br />#include&lt;iostream&gt; <br />using namespace std; <br />#define MAX 10000 <br />struct Node{ <br />&nbsp;&nbsp; int data; <br />&nbsp;&nbsp; Node *next; <br />}; <br />void output(Node *head,int pos) <br />{ <br />&nbsp;&nbsp; if(!head-&gt;next&amp;&amp;!head-&gt;data)return; <br />&nbsp;&nbsp; output(head-&gt;next,pos-1); <br />&nbsp;&nbsp; cout&lt;&lt;head-&gt;data;<br />&nbsp;&nbsp; if(!pos)cout&lt;&lt;".";<br />} <br />void Mul(char *a,char *b,int pos)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />{ <br />&nbsp;&nbsp; char *ap=a,*bp=b; <br />&nbsp;&nbsp; Node *head=0; <br />&nbsp;&nbsp; head=new Node;head-&gt;data=0,head-&gt;next=0;&nbsp;&nbsp; //头 <br />&nbsp;&nbsp; Node *p,*q=head,*p1; <br />&nbsp;&nbsp; int temp=0,temp1,bbit; <br />&nbsp;&nbsp; while(*bp)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //若乘数不为空 ,继续. <br />&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=q-&gt;next;p1=q; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bbit=*bp-48;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //把当前位转为整型 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(*ap||temp)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //若被乘数不空,继续 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!p)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //若要操作的结点为空,申请之 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=new Node; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p-&gt;data=0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p-&gt;next=0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1-&gt;next=p; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(*ap==0)temp1=temp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else { temp1=(p1-&gt;data)+(*ap-48)*bbit+temp;ap++; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1-&gt;data=temp1%10;&nbsp;&nbsp;&nbsp; //留当前位 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp=temp1/10;&nbsp;&nbsp;&nbsp; //进位以int的形式留下. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1=p;p=p-&gt;next;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //被乘数到下一位 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ap=a;bp++;q=q-&gt;next;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //q进下一位 <br />&nbsp;&nbsp; } <br />&nbsp;&nbsp; p=head; <br />&nbsp;&nbsp; output(p,pos);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //显示 <br />&nbsp;&nbsp; cout&lt;&lt;endl; <br />&nbsp;&nbsp; while(head)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //释放空间 <br />&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=head-&gt;next; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete head; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; head=p; <br />&nbsp;&nbsp; } <br />} <br />int main() <br />{ <br />&nbsp;&nbsp; cout&lt;&lt;"请输入两个数"&lt;&lt;endl; <br />&nbsp;&nbsp; char test1[MAX],test2[MAX],*p; <br />&nbsp;&nbsp; int pos=0;<br />&nbsp;&nbsp; cin.getline(test1,MAX,'\n'); <br />&nbsp;&nbsp; cin.getline(test2,MAX,'\n');<br />&nbsp;&nbsp; if(p=strchr(test1,'.'))<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos+=strlen(test1)-(p-test1)-1; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *(p-1)=*p;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }while(*p);<br />&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; if(p=strchr(test2,'.'))<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos+=strlen(test2)-(p-test2)-1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *(p-1)=*p;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }while(*p);<br />&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; Mul(strrev(test1),strrev(test2),pos); <br />&nbsp;&nbsp; system("PAUSE"); <br />&nbsp;&nbsp; return 0; <br />} </p>
<p>&nbsp;</p>
<p>本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/hanlin1985/archive/2008/10/10/3048605.aspx</font></p><img src ="http://www.cppblog.com/dotaqop/aggbug/148190.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-07 10:25 <a href="http://www.cppblog.com/dotaqop/articles/148190.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用C++写一个函数，将其中的\t都转换成4个*</title><link>http://www.cppblog.com/dotaqop/articles/148047.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Sat, 04 Jun 2011 06:04:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/148047.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/148047.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/148047.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/148047.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/148047.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img id="Codehighlighter1_82_500_Open_Image" onclick="this.style.display='none'; Codehighlighter1_82_500_Open_Text.style.display='none'; Codehighlighter1_82_500_Closed_Image.style.display='inline'; Codehighlighter1_82_500_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_82_500_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_82_500_Closed_Text.style.display='none'; Codehighlighter1_82_500_Open_Image.style.display='inline'; Codehighlighter1_82_500_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;change(</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;buf,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;buf_len)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_82_500_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_82_500_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;str_len&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">strlen(buf);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt_tab&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img id="Codehighlighter1_167_207_Open_Image" onclick="this.style.display='none'; Codehighlighter1_167_207_Open_Text.style.display='none'; Codehighlighter1_167_207_Closed_Image.style.display='inline'; Codehighlighter1_167_207_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_167_207_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_167_207_Closed_Text.style.display='none'; Codehighlighter1_167_207_Open_Image.style.display='inline'; Codehighlighter1_167_207_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;buf[i]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_167_207_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_167_207_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(buf[i]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\t</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt_tab</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;new_len</span><span style="color: #000000">=</span><span style="color: #000000">str_len</span><span style="color: #000000">+</span><span style="color: #000000">3</span><span style="color: #000000">*</span><span style="color: #000000">cnt_tab;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(buf_len&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;new_len</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /><img id="Codehighlighter1_303_484_Open_Image" onclick="this.style.display='none'; Codehighlighter1_303_484_Open_Text.style.display='none'; Codehighlighter1_303_484_Closed_Image.style.display='inline'; Codehighlighter1_303_484_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_303_484_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_303_484_Closed_Text.style.display='none'; Codehighlighter1_303_484_Open_Image.style.display='inline'; Codehighlighter1_303_484_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(cnt_tab&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_303_484_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_303_484_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_330_368_Open_Image" onclick="this.style.display='none'; Codehighlighter1_330_368_Open_Text.style.display='none'; Codehighlighter1_330_368_Closed_Image.style.display='inline'; Codehighlighter1_330_368_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_330_368_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_330_368_Closed_Text.style.display='none'; Codehighlighter1_330_368_Open_Image.style.display='inline'; Codehighlighter1_330_368_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(buf[str_len]</span><span style="color: #000000">!=</span><span style="color: #000000">'</span><span style="color: #000000">\t</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_330_368_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_330_368_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf[new_len</span><span style="color: #000000">--</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">buf[str_len</span><span style="color: #000000">--</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_376_481_Open_Image" onclick="this.style.display='none'; Codehighlighter1_376_481_Open_Text.style.display='none'; Codehighlighter1_376_481_Closed_Image.style.display='inline'; Codehighlighter1_376_481_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_376_481_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_376_481_Closed_Text.style.display='none'; Codehighlighter1_376_481_Open_Image.style.display='inline'; Codehighlighter1_376_481_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_376_481_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_376_481_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_401_430_Open_Image" onclick="this.style.display='none'; Codehighlighter1_401_430_Open_Text.style.display='none'; Codehighlighter1_401_430_Closed_Image.style.display='inline'; Codehighlighter1_401_430_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_401_430_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_401_430_Closed_Text.style.display='none'; Codehighlighter1_401_430_Open_Image.style.display='inline'; Codehighlighter1_401_430_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">4</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_401_430_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_401_430_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf[new_len</span><span style="color: #000000">--</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">*</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str_len</span><span style="color: #000000">--</span><span style="color: #000000">;</span><span style="color: #008000">//</span><span style="color: #008000">be&nbsp;careful!!!!!!!</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt_tab</span><span style="color: #000000">--</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_514_679_Open_Image" onclick="this.style.display='none'; Codehighlighter1_514_679_Open_Text.style.display='none'; Codehighlighter1_514_679_Closed_Image.style.display='inline'; Codehighlighter1_514_679_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_514_679_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_514_679_Closed_Text.style.display='none'; Codehighlighter1_514_679_Open_Image.style.display='inline'; Codehighlighter1_514_679_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_514_679_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_514_679_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;buf[</span><span style="color: #000000">100</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">1\t23\tba</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(change(buf,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(buf)</span><span style="color: #000000">/</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #0000ff">char</span><span style="color: #000000">)))<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;buf&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">buf长度不够不能转换!</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/148047.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-04 14:04 <a href="http://www.cppblog.com/dotaqop/articles/148047.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A，B从一堆玻璃球（共100个）里向外拿球</title><link>http://www.cppblog.com/dotaqop/articles/147994.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 03 Jun 2011 02:07:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/147994.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/147994.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/147994.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/147994.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/147994.html</trackback:ping><description><![CDATA[A，B从一堆玻璃球（共100个）里向外拿球，规则如下： <br />(1)A先拿，然后一人一次交替着拿；<br />(2)每次只能拿1个或2个或4个； <br />(3)谁拿最后一个球，谁就是最后的失败者； <br />问A，B谁将是失败者？写出你的判断步骤。 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdlib</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">ctime</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_89_665_Open_Image" onclick="this.style.display='none'; Codehighlighter1_89_665_Open_Text.style.display='none'; Codehighlighter1_89_665_Closed_Image.style.display='inline'; Codehighlighter1_89_665_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_89_665_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_89_665_Closed_Text.style.display='none'; Codehighlighter1_89_665_Open_Image.style.display='inline'; Codehighlighter1_89_665_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_89_665_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_89_665_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;srand((unsigned)time(NULL));<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_130_136_Open_Image" onclick="this.style.display='none'; Codehighlighter1_130_136_Open_Text.style.display='none'; Codehighlighter1_130_136_Closed_Image.style.display='inline'; Codehighlighter1_130_136_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_130_136_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_130_136_Closed_Text.style.display='none'; Codehighlighter1_130_136_Open_Image.style.display='inline'; Codehighlighter1_130_136_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;c[]</span><span style="color: #000000">=</span><span id="Codehighlighter1_130_136_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_130_136_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">2</span><span style="color: #000000">,</span><span style="color: #000000">4</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;aget,bget;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;aflag,bflag;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;sum</span><span style="color: #000000">=</span><span style="color: #000000">100</span><span style="color: #000000">;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_197_634_Open_Image" onclick="this.style.display='none'; Codehighlighter1_197_634_Open_Text.style.display='none'; Codehighlighter1_197_634_Closed_Image.style.display='inline'; Codehighlighter1_197_634_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_197_634_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_197_634_Closed_Text.style.display='none'; Codehighlighter1_197_634_Open_Image.style.display='inline'; Codehighlighter1_197_634_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span id="Codehighlighter1_197_634_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_197_634_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aflag</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_227_362_Open_Image" onclick="this.style.display='none'; Codehighlighter1_227_362_Open_Text.style.display='none'; Codehighlighter1_227_362_Closed_Image.style.display='inline'; Codehighlighter1_227_362_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_227_362_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_227_362_Closed_Text.style.display='none'; Codehighlighter1_227_362_Open_Image.style.display='inline'; Codehighlighter1_227_362_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(aflag)</span><span id="Codehighlighter1_227_362_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_227_362_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aget</span><span style="color: #000000">=</span><span style="color: #000000">c[rand()</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">];<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_266_355_Open_Image" onclick="this.style.display='none'; Codehighlighter1_266_355_Open_Text.style.display='none'; Codehighlighter1_266_355_Closed_Image.style.display='inline'; Codehighlighter1_266_355_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_266_355_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_266_355_Closed_Text.style.display='none'; Codehighlighter1_266_355_Open_Image.style.display='inline'; Codehighlighter1_266_355_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(aget</span><span style="color: #000000">&lt;=</span><span style="color: #000000">sum)</span><span id="Codehighlighter1_266_355_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_266_355_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="color: #000000">-=</span><span style="color: #000000">aget;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aflag</span><span style="color: #000000">=</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">A取走</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">aget</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">个球\t还剩下</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">sum</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">个球</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img id="Codehighlighter1_376_414_Open_Image" onclick="this.style.display='none'; Codehighlighter1_376_414_Open_Text.style.display='none'; Codehighlighter1_376_414_Closed_Image.style.display='inline'; Codehighlighter1_376_414_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_376_414_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_376_414_Closed_Text.style.display='none'; Codehighlighter1_376_414_Open_Image.style.display='inline'; Codehighlighter1_376_414_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(sum</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span id="Codehighlighter1_376_414_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_376_414_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">A是失败者</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bflag</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_444_579_Open_Image" onclick="this.style.display='none'; Codehighlighter1_444_579_Open_Text.style.display='none'; Codehighlighter1_444_579_Closed_Image.style.display='inline'; Codehighlighter1_444_579_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_444_579_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_444_579_Closed_Text.style.display='none'; Codehighlighter1_444_579_Open_Image.style.display='inline'; Codehighlighter1_444_579_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(bflag)</span><span id="Codehighlighter1_444_579_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_444_579_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bget</span><span style="color: #000000">=</span><span style="color: #000000">c[rand()</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">];<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img id="Codehighlighter1_483_572_Open_Image" onclick="this.style.display='none'; Codehighlighter1_483_572_Open_Text.style.display='none'; Codehighlighter1_483_572_Closed_Image.style.display='inline'; Codehighlighter1_483_572_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_483_572_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_483_572_Closed_Text.style.display='none'; Codehighlighter1_483_572_Open_Image.style.display='inline'; Codehighlighter1_483_572_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(bget</span><span style="color: #000000">&lt;=</span><span style="color: #000000">sum)</span><span id="Codehighlighter1_483_572_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_483_572_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="color: #000000">-=</span><span style="color: #000000">bget;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bflag</span><span style="color: #000000">=</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">B取走</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">bget</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">个球\t还剩下</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">sum</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">个球</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img id="Codehighlighter1_593_631_Open_Image" onclick="this.style.display='none'; Codehighlighter1_593_631_Open_Text.style.display='none'; Codehighlighter1_593_631_Closed_Image.style.display='inline'; Codehighlighter1_593_631_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_593_631_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_593_631_Closed_Text.style.display='none'; Codehighlighter1_593_631_Open_Image.style.display='inline'; Codehighlighter1_593_631_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(sum</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span id="Codehighlighter1_593_631_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_593_631_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">B是失败者</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">44</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div><br /><br /><img src ="http://www.cppblog.com/dotaqop/aggbug/147994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-03 10:07 <a href="http://www.cppblog.com/dotaqop/articles/147994.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>素数问题</title><link>http://www.cppblog.com/dotaqop/articles/147876.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Wed, 01 Jun 2011 07:39:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/147876.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/147876.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/147876.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/147876.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/147876.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<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"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img id="Codehighlighter1_67_385_Open_Image" onclick="this.style.display='none'; Codehighlighter1_67_385_Open_Text.style.display='none'; Codehighlighter1_67_385_Closed_Image.style.display='inline'; Codehighlighter1_67_385_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_67_385_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_67_385_Closed_Text.style.display='none'; Codehighlighter1_67_385_Open_Image.style.display='inline'; Codehighlighter1_67_385_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;int_devide(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nTest)</span><span id="Codehighlighter1_67_385_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_67_385_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_81_125_Open_Image" onclick="this.style.display='none'; Codehighlighter1_81_125_Open_Text.style.display='none'; Codehighlighter1_81_125_Closed_Image.style.display='inline'; Codehighlighter1_81_125_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_81_125_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_81_125_Closed_Text.style.display='none'; Codehighlighter1_81_125_Open_Image.style.display='inline'; Codehighlighter1_81_125_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;itpl[]</span><span style="color: #000000">=</span><span id="Codehighlighter1_81_125_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_81_125_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">2</span><span style="color: #000000">,</span><span style="color: #000000">3</span><span style="color: #000000">,</span><span style="color: #000000">5</span><span style="color: #000000">,</span><span style="color: #000000">7</span><span style="color: #000000">,</span><span style="color: #000000">11</span><span style="color: #000000">,</span><span style="color: #000000">13</span><span style="color: #000000">,</span><span style="color: #000000">17</span><span style="color: #000000">,</span><span style="color: #000000">19</span><span style="color: #000000">,</span><span style="color: #000000">23</span><span style="color: #000000">,</span><span style="color: #000000">29</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">,</span><span style="color: #000000">37</span><span style="color: #000000">,</span><span style="color: #000000">41</span><span style="color: #000000">,</span><span style="color: #000000">43</span><span style="color: #000000">,</span><span style="color: #000000">47</span><span style="color: #000000">,</span><span style="color: #000000">53</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">int_devide:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">nTest</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;=&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img id="Codehighlighter1_219_335_Open_Image" onclick="this.style.display='none'; Codehighlighter1_219_335_Open_Text.style.display='none'; Codehighlighter1_219_335_Closed_Image.style.display='inline'; Codehighlighter1_219_335_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_219_335_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_219_335_Closed_Text.style.display='none'; Codehighlighter1_219_335_Open_Image.style.display='inline'; Codehighlighter1_219_335_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;nTest</span><span style="color: #000000">!=</span><span style="color: #000000">1</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">i</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(itpl)</span><span style="color: #000000">/</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">);</span><span style="color: #000000">++</span><span style="color: #000000">i)</span><span id="Codehighlighter1_219_335_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_219_335_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(itpl[i]</span><span style="color: #000000">*</span><span style="color: #000000">itpl[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">nTest)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img id="Codehighlighter1_284_332_Open_Image" onclick="this.style.display='none'; Codehighlighter1_284_332_Open_Text.style.display='none'; Codehighlighter1_284_332_Closed_Image.style.display='inline'; Codehighlighter1_284_332_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_284_332_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_284_332_Closed_Text.style.display='none'; Codehighlighter1_284_332_Open_Image.style.display='inline'; Codehighlighter1_284_332_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(nTest</span><span style="color: #000000">%</span><span style="color: #000000">itpl[i]</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span id="Codehighlighter1_284_332_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_284_332_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">itpl[i]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">\t</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTest</span><span style="color: #000000">/=</span><span style="color: #000000">itpl[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(nTest</span><span style="color: #000000">!=</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">nTest</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_400_512_Open_Image" onclick="this.style.display='none'; Codehighlighter1_400_512_Open_Text.style.display='none'; Codehighlighter1_400_512_Closed_Image.style.display='inline'; Codehighlighter1_400_512_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_400_512_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_400_512_Closed_Text.style.display='none'; Codehighlighter1_400_512_Open_Image.style.display='inline'; Codehighlighter1_400_512_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_400_512_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_400_512_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">num;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">num;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int_devide(i);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;int_devide(num);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/147876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-06-01 15:39 <a href="http://www.cppblog.com/dotaqop/articles/147876.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从intANDchar.txt只读取字符并从小到大排序输出</title><link>http://www.cppblog.com/dotaqop/articles/146814.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 20 May 2011 06:20:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/146814.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/146814.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/146814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/146814.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/146814.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">fstream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">vector</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />typedef&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;T;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_133_398_Open_Image" onclick="this.style.display='none'; Codehighlighter1_133_398_Open_Text.style.display='none'; Codehighlighter1_133_398_Closed_Image.style.display='inline'; Codehighlighter1_133_398_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_133_398_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_133_398_Closed_Text.style.display='none'; Codehighlighter1_133_398_Open_Image.style.display='inline'; Codehighlighter1_133_398_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;sort(vector</span><span style="color: #000000">&lt;</span><span style="color: #000000">T</span><span style="color: #000000">&gt;</span><span style="color: #000000">::iterator&nbsp;a,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n)</span><span id="Codehighlighter1_133_398_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_133_398_Open_Text"><span style="color: #000000">{</span><span style="color: #008000">//</span><span style="color: #008000">快速排序</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(n</span><span style="color: #000000">&lt;=</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="color: #000000">*</span><span style="color: #000000">a,a[n</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">1</span><span style="color: #000000">]);<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000">&lt;</span><span style="color: #000000">T</span><span style="color: #000000">&gt;</span><span style="color: #000000">::iterator&nbsp;L</span><span style="color: #000000">=</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000">&lt;</span><span style="color: #000000">T</span><span style="color: #000000">&gt;</span><span style="color: #000000">::iterator&nbsp;R</span><span style="color: #000000">=</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;V</span><span style="color: #000000">=*</span><span style="color: #000000">a;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_258_337_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_337_Open_Text.style.display='none'; Codehighlighter1_258_337_Closed_Image.style.display='inline'; Codehighlighter1_258_337_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_258_337_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_258_337_Closed_Text.style.display='none'; Codehighlighter1_258_337_Open_Image.style.display='inline'; Codehighlighter1_258_337_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(L</span><span style="color: #000000">&lt;</span><span style="color: #000000">R)</span><span id="Codehighlighter1_258_337_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_258_337_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">L</span><span style="color: #000000">&lt;</span><span style="color: #000000">V&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;L</span><span style="color: #000000">&lt;</span><span style="color: #000000">R)&nbsp;L</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">R</span><span style="color: #000000">&gt;=</span><span style="color: #000000">V&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;R</span><span style="color: #000000">&gt;</span><span style="color: #000000">a)&nbsp;R</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(L</span><span style="color: #000000">&lt;</span><span style="color: #000000">R)&nbsp;swap(</span><span style="color: #000000">*</span><span style="color: #000000">L,</span><span style="color: #000000">*</span><span style="color: #000000">R);<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(V</span><span style="color: #000000">&gt;*</span><span style="color: #000000">R)&nbsp;swap(</span><span style="color: #000000">*</span><span style="color: #000000">a,</span><span style="color: #000000">*</span><span style="color: #000000">R);<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sort(a,R</span><span style="color: #000000">-</span><span style="color: #000000">a);<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sort(R</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">,n</span><span style="color: #000000">-</span><span style="color: #000000">(R</span><span style="color: #000000">-</span><span style="color: #000000">a)</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">);<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img id="Codehighlighter1_412_1592_Open_Image" onclick="this.style.display='none'; Codehighlighter1_412_1592_Open_Text.style.display='none'; Codehighlighter1_412_1592_Closed_Image.style.display='inline'; Codehighlighter1_412_1592_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_412_1592_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_412_1592_Closed_Text.style.display='none'; Codehighlighter1_412_1592_Open_Image.style.display='inline'; Codehighlighter1_412_1592_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_412_1592_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_412_1592_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;ifstream&nbsp;fin(</span><span style="color: #000000">"</span><span style="color: #000000">C:\\intANDchar.txt</span><span style="color: #000000">"</span><span style="color: #000000">);</span><span style="color: #008000">//</span><span style="color: #008000">.txt中l后面我自己敲了一个空格</span><span style="color: #008000"><br /></span><span style="color: #008080">26</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;ch;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;temp;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000">&lt;</span><span style="color: #000000">T</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;array;<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img id="Codehighlighter1_529_566_Open_Image" onclick="this.style.display='none'; Codehighlighter1_529_566_Open_Text.style.display='none'; Codehighlighter1_529_566_Closed_Image.style.display='inline'; Codehighlighter1_529_566_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_529_566_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_529_566_Closed_Text.style.display='none'; Codehighlighter1_529_566_Open_Image.style.display='inline'; Codehighlighter1_529_566_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">fin)</span><span id="Codehighlighter1_529_566_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_529_566_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">file&nbsp;error!</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000">1</span><span style="color: #000000">);<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">34</span><span style="color: #000000"><img id="Codehighlighter1_586_851_Open_Image" onclick="this.style.display='none'; Codehighlighter1_586_851_Open_Text.style.display='none'; Codehighlighter1_586_851_Closed_Image.style.display='inline'; Codehighlighter1_586_851_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_586_851_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_586_851_Closed_Text.style.display='none'; Codehighlighter1_586_851_Open_Image.style.display='inline'; Codehighlighter1_586_851_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">fin.eof())</span><span id="Codehighlighter1_586_851_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_586_851_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch</span><span style="color: #000000">=</span><span style="color: #000000">fin.peek();<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img id="Codehighlighter1_627_647_Open_Image" onclick="this.style.display='none'; Codehighlighter1_627_647_Open_Text.style.display='none'; Codehighlighter1_627_647_Closed_Image.style.display='inline'; Codehighlighter1_627_647_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_627_647_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_627_647_Closed_Text.style.display='none'; Codehighlighter1_627_647_Open_Image.style.display='inline'; Codehighlighter1_627_647_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ch</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">9</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">ch</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span id="Codehighlighter1_627_647_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_627_647_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">n;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img id="Codehighlighter1_696_757_Open_Image" onclick="this.style.display='none'; Codehighlighter1_696_757_Open_Text.style.display='none'; Codehighlighter1_696_757_Closed_Image.style.display='inline'; Codehighlighter1_696_757_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_696_757_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_696_757_Closed_Text.style.display='none'; Codehighlighter1_696_757_Open_Image.style.display='inline'; Codehighlighter1_696_757_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ch</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">z</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">ch</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">a</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;ch</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">Z</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">ch</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span id="Codehighlighter1_696_757_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_696_757_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">ch;&nbsp;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ch</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array.push_back(ch);&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">44</span><span style="color: #000000"><img id="Codehighlighter1_765_848_Open_Image" onclick="this.style.display='none'; Codehighlighter1_765_848_Open_Text.style.display='none'; Codehighlighter1_765_848_Closed_Image.style.display='inline'; Codehighlighter1_765_848_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_765_848_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_765_848_Closed_Text.style.display='none'; Codehighlighter1_765_848_Open_Image.style.display='inline'; Codehighlighter1_765_848_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span id="Codehighlighter1_765_848_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_765_848_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.</span><span style="color: #0000ff">get</span><span style="color: #000000">(temp);<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">temp[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">temp</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array.push_back(temp);<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">49</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">50</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;fin.close();<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sort(array.begin(),array.size());<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img id="Codehighlighter1_903_977_Open_Image" onclick="this.style.display='none'; Codehighlighter1_903_977_Open_Text.style.display='none'; Codehighlighter1_903_977_Closed_Image.style.display='inline'; Codehighlighter1_903_977_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_903_977_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_903_977_Closed_Text.style.display='none'; Codehighlighter1_903_977_Open_Image.style.display='inline'; Codehighlighter1_903_977_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_903_977_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_903_977_Open_Text"><span style="color: #808080">////////////////////////////////////////////////////////////////////////</span><span style="color: #008000">//</span><span style="color: #808080"></span></span><br /><span style="color: #008080">53</span><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">排序后输出</span><span style="color: #008000"><br /></span><span style="color: #008080">54</span><span style="color: #008000"><img id="Codehighlighter1_988_1062_Open_Image" onclick="this.style.display='none'; Codehighlighter1_988_1062_Open_Text.style.display='none'; Codehighlighter1_988_1062_Closed_Image.style.display='inline'; Codehighlighter1_988_1062_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_988_1062_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_988_1062_Closed_Text.style.display='none'; Codehighlighter1_988_1062_Open_Image.style.display='inline'; Codehighlighter1_988_1062_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_988_1062_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_988_1062_Open_Text"><span style="color: #808080">////////////////////////////////////////////////////////////////////////</span><span style="color: #008000">//</span><span style="color: #808080"></span></span><br /><span style="color: #008080">55</span><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">从小到大排完序如下：</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[0]:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[1]:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[2]:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[</span><span style="color: #000000">2</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">59</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[3]:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[</span><span style="color: #000000">3</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[4]:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[</span><span style="color: #000000">4</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">=========================</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">62</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[5]:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[</span><span style="color: #000000">5</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array.size()=</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array.size()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">array[]的最后一个元素是:[</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[array.size()</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">]</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img id="Codehighlighter1_1539_1560_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1539_1560_Open_Text.style.display='none'; Codehighlighter1_1539_1560_Closed_Image.style.display='inline'; Codehighlighter1_1539_1560_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1539_1560_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1539_1560_Closed_Text.style.display='none'; Codehighlighter1_1539_1560_Open_Image.style.display='inline'; Codehighlighter1_1539_1560_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(vector</span><span style="color: #000000">&lt;</span><span style="color: #000000">T</span><span style="color: #000000">&gt;</span><span style="color: #000000">::size_type&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">array.size();i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span id="Codehighlighter1_1539_1560_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1539_1560_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">array[i];<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">68</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /></span><span style="color: #008080">69</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">70</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">71</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img height="651" alt="" src="http://www.cppblog.com/images/cppblog_com/dotaqop/qq.jpg" width="462" border="0" longdesc="" /><br />&nbsp;<strong><span>l后面我自己敲了1个空格<br /></span><span style="color: red; font-family: Arial">注意q后面的</span><br />temp[<br />]</strong>  <img src ="http://www.cppblog.com/dotaqop/aggbug/146814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-05-20 14:20 <a href="http://www.cppblog.com/dotaqop/articles/146814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用两个栈实现队列</title><link>http://www.cppblog.com/dotaqop/articles/146811.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 20 May 2011 05:18:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/146811.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/146811.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/146811.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/146811.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/146811.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<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"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cassert</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">List.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #008000">//</span><span style="color: #008000">链表栈</span><span style="color: #008000"><br /><img id="Codehighlighter1_54_291_Open_Image" onclick="this.style.display='none'; Codehighlighter1_54_291_Open_Text.style.display='none'; Codehighlighter1_54_291_Closed_Image.style.display='inline'; Codehighlighter1_54_291_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_54_291_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_54_291_Closed_Text.style.display='none'; Codehighlighter1_54_291_Open_Image.style.display='inline'; Codehighlighter1_54_291_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Stack</span><span id="Codehighlighter1_54_291_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_54_291_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;L;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /><img id="Codehighlighter1_101_120_Open_Image" onclick="this.style.display='none'; Codehighlighter1_101_120_Open_Text.style.display='none'; Codehighlighter1_101_120_Closed_Image.style.display='inline'; Codehighlighter1_101_120_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_101_120_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_101_120_Closed_Text.style.display='none'; Codehighlighter1_101_120_Open_Image.style.display='inline'; Codehighlighter1_101_120_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;push(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;T</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;t)</span><span id="Codehighlighter1_101_120_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_101_120_Open_Text"><span style="color: #000000">{L.insert_front(t);}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_133_153_Open_Image" onclick="this.style.display='none'; Codehighlighter1_133_153_Open_Text.style.display='none'; Codehighlighter1_133_153_Closed_Image.style.display='inline'; Codehighlighter1_133_153_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_133_153_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_133_153_Closed_Text.style.display='none'; Codehighlighter1_133_153_Open_Image.style.display='inline'; Codehighlighter1_133_153_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;top()</span><span id="Codehighlighter1_133_153_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_133_153_Open_Text"><span style="color: #000000">{</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;L.getHead();}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_169_191_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_191_Open_Text.style.display='none'; Codehighlighter1_169_191_Closed_Image.style.display='inline'; Codehighlighter1_169_191_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_169_191_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_169_191_Closed_Text.style.display='none'; Codehighlighter1_169_191_Open_Image.style.display='inline'; Codehighlighter1_169_191_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;pop()</span><span id="Codehighlighter1_169_191_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_169_191_Open_Text"><span style="color: #000000">{L.erase(L.getHead());}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_209_227_Open_Image" onclick="this.style.display='none'; Codehighlighter1_209_227_Open_Text.style.display='none'; Codehighlighter1_209_227_Closed_Image.style.display='inline'; Codehighlighter1_209_227_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_209_227_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_209_227_Closed_Text.style.display='none'; Codehighlighter1_209_227_Open_Image.style.display='inline'; Codehighlighter1_209_227_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;empty()</span><span id="Codehighlighter1_209_227_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_209_227_Open_Text"><span style="color: #000000">{</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;L.empty();}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_245_256_Open_Image" onclick="this.style.display='none'; Codehighlighter1_245_256_Open_Text.style.display='none'; Codehighlighter1_245_256_Closed_Image.style.display='inline'; Codehighlighter1_245_256_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_245_256_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_245_256_Closed_Text.style.display='none'; Codehighlighter1_245_256_Open_Image.style.display='inline'; Codehighlighter1_245_256_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;clear()</span><span id="Codehighlighter1_245_256_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_245_256_Open_Text"><span style="color: #000000">{L.clear();}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_272_289_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_289_Open_Text.style.display='none'; Codehighlighter1_272_289_Closed_Image.style.display='inline'; Codehighlighter1_272_289_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_272_289_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_272_289_Closed_Text.style.display='none'; Codehighlighter1_272_289_Open_Image.style.display='inline'; Codehighlighter1_272_289_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;size()</span><span id="Codehighlighter1_272_289_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_272_289_Open_Text"><span style="color: #000000">{</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;L.size();}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /><img id="Codehighlighter1_294_1012_Open_Image" onclick="this.style.display='none'; Codehighlighter1_294_1012_Open_Text.style.display='none'; Codehighlighter1_294_1012_Closed_Image.style.display='inline'; Codehighlighter1_294_1012_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_294_1012_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_294_1012_Closed_Text.style.display='none'; Codehighlighter1_294_1012_Open_Image.style.display='inline'; Codehighlighter1_294_1012_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_294_1012_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_294_1012_Open_Text"><span style="color: #808080">////////////</span><span style="color: #008000">顺序栈<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/class&nbsp;Stack1{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;a[10];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;num;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/public:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;Stack1():num(0){}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;push(const&nbsp;T&amp;&nbsp;t){<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(full())<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;"stack&nbsp;overflow";<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[num++]=t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;top(){<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(empty())<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;"no&nbsp;top&nbsp;stack";<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;a[num-1];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;pop(){<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(empty())<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;"empty&nbsp;stack";<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num--;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;empty(){return&nbsp;num==0;}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;full(){return&nbsp;num==10;}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;size(){return&nbsp;num;}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" /></span><span style="color: #808080">/////////</span><span style="color: #008000">/};</span><span style="color: #808080"></span></span><br /><img id="Codehighlighter1_1024_1523_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1024_1523_Open_Text.style.display='none'; Codehighlighter1_1024_1523_Closed_Image.style.display='inline'; Codehighlighter1_1024_1523_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_1024_1523_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1024_1523_Closed_Text.style.display='none'; Codehighlighter1_1024_1523_Open_Image.style.display='inline'; Codehighlighter1_1024_1523_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Queue</span><span id="Codehighlighter1_1024_1523_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1024_1523_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Stack&nbsp;s1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Stack&nbsp;s2;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /><img id="Codehighlighter1_1093_1119_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1093_1119_Open_Text.style.display='none'; Codehighlighter1_1093_1119_Closed_Image.style.display='inline'; Codehighlighter1_1093_1119_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1093_1119_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1093_1119_Closed_Text.style.display='none'; Codehighlighter1_1093_1119_Open_Image.style.display='inline'; Codehighlighter1_1093_1119_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;appendTail(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;T</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;t)</span><span id="Codehighlighter1_1093_1119_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1093_1119_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s1.push(t);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_1142_1294_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1142_1294_Open_Text.style.display='none'; Codehighlighter1_1142_1294_Closed_Image.style.display='inline'; Codehighlighter1_1142_1294_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1142_1294_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1142_1294_Closed_Text.style.display='none'; Codehighlighter1_1142_1294_Open_Image.style.display='inline'; Codehighlighter1_1142_1294_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;deletehead()</span><span id="Codehighlighter1_1142_1294_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1142_1294_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_1166_1241_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1166_1241_Open_Text.style.display='none'; Codehighlighter1_1166_1241_Closed_Image.style.display='inline'; Codehighlighter1_1166_1241_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1166_1241_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1166_1241_Closed_Text.style.display='none'; Codehighlighter1_1166_1241_Open_Image.style.display='inline'; Codehighlighter1_1166_1241_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(s2.empty())</span><span id="Codehighlighter1_1166_1241_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1166_1241_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_1189_1231_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1189_1231_Open_Text.style.display='none'; Codehighlighter1_1189_1231_Closed_Image.style.display='inline'; Codehighlighter1_1189_1231_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1189_1231_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1189_1231_Closed_Text.style.display='none'; Codehighlighter1_1189_1231_Open_Image.style.display='inline'; Codehighlighter1_1189_1231_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s1.empty())</span><span id="Codehighlighter1_1189_1231_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1189_1231_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s2.push(s1.top());<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s1.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert(s2.size()</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s2.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_1307_1472_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1307_1472_Open_Text.style.display='none'; Codehighlighter1_1307_1472_Closed_Image.style.display='inline'; Codehighlighter1_1307_1472_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1307_1472_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1307_1472_Closed_Text.style.display='none'; Codehighlighter1_1307_1472_Open_Image.style.display='inline'; Codehighlighter1_1307_1472_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;top()</span><span id="Codehighlighter1_1307_1472_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1307_1472_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_1325_1412_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1325_1412_Open_Text.style.display='none'; Codehighlighter1_1325_1412_Closed_Image.style.display='inline'; Codehighlighter1_1325_1412_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1325_1412_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1325_1412_Closed_Text.style.display='none'; Codehighlighter1_1325_1412_Open_Image.style.display='inline'; Codehighlighter1_1325_1412_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(s2.empty())</span><span id="Codehighlighter1_1325_1412_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1325_1412_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_1348_1402_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1348_1402_Open_Text.style.display='none'; Codehighlighter1_1348_1402_Closed_Image.style.display='inline'; Codehighlighter1_1348_1402_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1348_1402_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1348_1402_Closed_Text.style.display='none'; Codehighlighter1_1348_1402_Open_Image.style.display='inline'; Codehighlighter1_1348_1402_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s1.empty())</span><span id="Codehighlighter1_1348_1402_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1348_1402_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s2.push(s1.top());<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s1.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert(s2.size()</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;s2.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_1490_1521_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1490_1521_Open_Text.style.display='none'; Codehighlighter1_1490_1521_Closed_Image.style.display='inline'; Codehighlighter1_1490_1521_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1490_1521_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1490_1521_Closed_Text.style.display='none'; Codehighlighter1_1490_1521_Open_Image.style.display='inline'; Codehighlighter1_1490_1521_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;empty()</span><span id="Codehighlighter1_1490_1521_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1490_1521_Open_Text"><span style="color: #000000">{</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;s1.empty()</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">s2.empty();}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_1537_1889_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1537_1889_Open_Text.style.display='none'; Codehighlighter1_1537_1889_Closed_Image.style.display='inline'; Codehighlighter1_1537_1889_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_1537_1889_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1537_1889_Closed_Text.style.display='none'; Codehighlighter1_1537_1889_Open_Image.style.display='inline'; Codehighlighter1_1537_1889_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_1537_1889_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1537_1889_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Queue&nbsp;s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.appendTail(</span><span style="color: #000000">1.0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.appendTail(</span><span style="color: #000000">2.0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.deletehead();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.appendTail(</span><span style="color: #000000">3.0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.appendTail(</span><span style="color: #000000">4.0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.deletehead();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.deletehead();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;s.appendTail(</span><span style="color: #000000">5.0</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout.setf(ios::showpoint);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout.precision(</span><span style="color: #000000">10</span><span style="color: #000000">);<br /><img id="Codehighlighter1_1788_1852_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1788_1852_Open_Text.style.display='none'; Codehighlighter1_1788_1852_Closed_Image.style.display='inline'; Codehighlighter1_1788_1852_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1788_1852_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1788_1852_Closed_Text.style.display='none'; Codehighlighter1_1788_1852_Open_Image.style.display='inline'; Codehighlighter1_1788_1852_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty())</span><span id="Codehighlighter1_1788_1852_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1788_1852_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">s.top()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.deletehead();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/dotaqop/aggbug/146811.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-05-20 13:18 <a href="http://www.cppblog.com/dotaqop/articles/146811.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>链表类 List.h</title><link>http://www.cppblog.com/dotaqop/articles/146809.html</link><dc:creator>Hsssssss</dc:creator><author>Hsssssss</author><pubDate>Fri, 20 May 2011 05:15:00 GMT</pubDate><guid>http://www.cppblog.com/dotaqop/articles/146809.html</guid><wfw:comment>http://www.cppblog.com/dotaqop/comments/146809.html</wfw:comment><comments>http://www.cppblog.com/dotaqop/articles/146809.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dotaqop/comments/commentRss/146809.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dotaqop/services/trackbacks/146809.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#pragma&nbsp;once#include&nbsp;&lt;iostream&gt;using&nbsp;namespace&nbsp;std;#include&nbsp;&lt;string&...&nbsp;&nbsp;<a href='http://www.cppblog.com/dotaqop/articles/146809.html'>阅读全文</a><img src ="http://www.cppblog.com/dotaqop/aggbug/146809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dotaqop/" target="_blank">Hsssssss</a> 2011-05-20 13:15 <a href="http://www.cppblog.com/dotaqop/articles/146809.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>