﻿<?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++博客-二进制空间-文章分类-Ar!thmEt!c.Self</title><link>http://www.cppblog.com/asp/category/2877.html</link><description>See, I'm living...</description><language>zh-cn</language><lastBuildDate>Wed, 21 May 2008 18:14:32 GMT</lastBuildDate><pubDate>Wed, 21 May 2008 18:14:32 GMT</pubDate><ttl>60</ttl><item><title>中缀表达式转后缀表达式</title><link>http://www.cppblog.com/asp/articles/14265.html</link><dc:creator>Asp</dc:creator><author>Asp</author><pubDate>Thu, 26 Oct 2006 16:05:00 GMT</pubDate><guid>http://www.cppblog.com/asp/articles/14265.html</guid><wfw:comment>http://www.cppblog.com/asp/comments/14265.html</wfw:comment><comments>http://www.cppblog.com/asp/articles/14265.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/asp/comments/commentRss/14265.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/asp/services/trackbacks/14265.html</trackback:ping><description><![CDATA[
		<font size="2">    中缀表达式转后缀表达式……</font>
		<br />
		<br />
		<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">
				<img id="Codehighlighter1_0_111_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_111_Open_Text.style.display='none'; Codehighlighter1_0_111_Closed_Image.style.display='inline'; Codehighlighter1_0_111_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_0_111_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_111_Closed_Text.style.display='none'; Codehighlighter1_0_111_Open_Image.style.display='inline'; Codehighlighter1_0_111_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span id="Codehighlighter1_0_111_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_0_111_Open_Text">
						<span style="COLOR: #008000">/*</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />test case:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />2*(3+4)-8/2<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />(2*3+(2+5*2-10))/(8/2)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />15+10*(50*2-5)/2<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />15+10*(50*2-5)/3<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />1.5*2.3*(3.7-2.13*3.2)-8.0<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span>
						<span style="COLOR: #008000">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> stdio.h </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">string</span>
				<span style="COLOR: #000000">.h </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N 1000</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> b[N],c,stack[</span>
				<span style="COLOR: #000000">100</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bn,sn,isnum,endflag</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/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> midtoback()<br /><img id="Codehighlighter1_241_1430_Open_Image" onclick="this.style.display='none'; Codehighlighter1_241_1430_Open_Text.style.display='none'; Codehighlighter1_241_1430_Closed_Image.style.display='inline'; Codehighlighter1_241_1430_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_241_1430_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_241_1430_Closed_Text.style.display='none'; Codehighlighter1_241_1430_Open_Image.style.display='inline'; Codehighlighter1_241_1430_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_241_1430_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" />
				</span>
				<span id="Codehighlighter1_241_1430_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bn</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" />    sn</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" />    isnum</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" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">((c</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">getchar())</span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000">EOF</span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000">c</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 id="Codehighlighter1_306_1366_Open_Image" onclick="this.style.display='none'; Codehighlighter1_306_1366_Open_Text.style.display='none'; Codehighlighter1_306_1366_Closed_Image.style.display='inline'; Codehighlighter1_306_1366_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_306_1366_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_306_1366_Closed_Text.style.display='none'; Codehighlighter1_306_1366_Open_Image.style.display='inline'; Codehighlighter1_306_1366_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_306_1366_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" />
						</span>
						<span id="Codehighlighter1_306_1366_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">switch</span>
								<span style="COLOR: #000000">(c)<br /><img id="Codehighlighter1_322_1363_Open_Image" onclick="this.style.display='none'; Codehighlighter1_322_1363_Open_Text.style.display='none'; Codehighlighter1_322_1363_Closed_Image.style.display='inline'; Codehighlighter1_322_1363_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_322_1363_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_322_1363_Closed_Text.style.display='none'; Codehighlighter1_322_1363_Open_Image.style.display='inline'; Codehighlighter1_322_1363_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_322_1363_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" />
								</span>
								<span id="Codehighlighter1_322_1363_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">case</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(isnum</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) b[bn</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stack[</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">sn]</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">case</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(isnum</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) b[bn</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000">(sn</span>
										<span style="COLOR: #000000">&gt;=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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 id="Codehighlighter1_495_544_Open_Image" onclick="this.style.display='none'; Codehighlighter1_495_544_Open_Text.style.display='none'; Codehighlighter1_495_544_Closed_Image.style.display='inline'; Codehighlighter1_495_544_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_495_544_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_495_544_Closed_Text.style.display='none'; Codehighlighter1_495_544_Open_Image.style.display='inline'; Codehighlighter1_495_544_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_495_544_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" />
										</span>
										<span id="Codehighlighter1_495_544_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                b[bn</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">stack[sn</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                stack[sn</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">]</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/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stack[sn</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">]</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" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">case</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(isnum</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) b[bn</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000">(sn</span>
										<span style="COLOR: #000000">&gt;=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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 id="Codehighlighter1_662_711_Open_Image" onclick="this.style.display='none'; Codehighlighter1_662_711_Open_Text.style.display='none'; Codehighlighter1_662_711_Closed_Image.style.display='inline'; Codehighlighter1_662_711_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_662_711_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_662_711_Closed_Text.style.display='none'; Codehighlighter1_662_711_Open_Image.style.display='inline'; Codehighlighter1_662_711_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_662_711_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" />
										</span>
										<span id="Codehighlighter1_662_711_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                b[bn</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">stack[sn</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                stack[sn</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">]</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/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stack[</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">sn]</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">case</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(isnum</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) b[bn</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000">(sn</span>
										<span style="COLOR: #000000">&gt;=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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 id="Codehighlighter1_831_880_Open_Image" onclick="this.style.display='none'; Codehighlighter1_831_880_Open_Text.style.display='none'; Codehighlighter1_831_880_Closed_Image.style.display='inline'; Codehighlighter1_831_880_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_831_880_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_831_880_Closed_Text.style.display='none'; Codehighlighter1_831_880_Open_Image.style.display='inline'; Codehighlighter1_831_880_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_831_880_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" />
										</span>
										<span id="Codehighlighter1_831_880_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                b[bn</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">stack[sn</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                stack[sn</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">]</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/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stack[</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">sn]</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">case</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(isnum</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) b[bn</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000">(sn</span>
										<span style="COLOR: #000000">&gt;=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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 id="Codehighlighter1_1032_1081_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1032_1081_Open_Text.style.display='none'; Codehighlighter1_1032_1081_Closed_Image.style.display='inline'; Codehighlighter1_1032_1081_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1032_1081_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1032_1081_Closed_Text.style.display='none'; Codehighlighter1_1032_1081_Open_Image.style.display='inline'; Codehighlighter1_1032_1081_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_1032_1081_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" />
										</span>
										<span id="Codehighlighter1_1032_1081_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                b[bn</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">stack[sn</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                stack[sn</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">]</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/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stack[</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">sn]</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">case</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(isnum</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) b[bn</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000">(sn</span>
										<span style="COLOR: #000000">&gt;=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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">&amp;&amp;</span>
										<span style="COLOR: #000000">stack[sn]</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 id="Codehighlighter1_1233_1282_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1233_1282_Open_Text.style.display='none'; Codehighlighter1_1233_1282_Closed_Image.style.display='inline'; Codehighlighter1_1233_1282_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1233_1282_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1233_1282_Closed_Text.style.display='none'; Codehighlighter1_1233_1282_Open_Image.style.display='inline'; Codehighlighter1_1233_1282_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_1233_1282_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" />
										</span>
										<span id="Codehighlighter1_1233_1282_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                b[bn</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">stack[sn</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                stack[sn</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">]</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/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stack[</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">sn]</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">default</span>
										<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            isnum</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" />            b[bn</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">]</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">c;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">(sn</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" />        b[bn</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">]</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">stack[sn</span>
						<span style="COLOR: #000000">--</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">(c</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">) endflag</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/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_1444_1576_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1444_1576_Open_Text.style.display='none'; Codehighlighter1_1444_1576_Closed_Image.style.display='inline'; Codehighlighter1_1444_1576_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1444_1576_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1444_1576_Closed_Text.style.display='none'; Codehighlighter1_1444_1576_Open_Image.style.display='inline'; Codehighlighter1_1444_1576_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1444_1576_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" />
				</span>
				<span id="Codehighlighter1_1444_1576_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">(endflag</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_1466_1563_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1466_1563_Open_Text.style.display='none'; Codehighlighter1_1466_1563_Closed_Image.style.display='inline'; Codehighlighter1_1466_1563_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1466_1563_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1466_1563_Closed_Text.style.display='none'; Codehighlighter1_1466_1563_Open_Image.style.display='inline'; Codehighlighter1_1466_1563_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1466_1563_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" />
						</span>
						<span id="Codehighlighter1_1466_1563_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        memset(stack,</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(stack));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        memset(b,</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(b));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        midtoback();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%s\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,b);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</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/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
<img src ="http://www.cppblog.com/asp/aggbug/14265.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/asp/" target="_blank">Asp</a> 2006-10-27 00:05 <a href="http://www.cppblog.com/asp/articles/14265.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>归并排序+求逆序数</title><link>http://www.cppblog.com/asp/articles/14261.html</link><dc:creator>Asp</dc:creator><author>Asp</author><pubDate>Thu, 26 Oct 2006 15:01:00 GMT</pubDate><guid>http://www.cppblog.com/asp/articles/14261.html</guid><wfw:comment>http://www.cppblog.com/asp/comments/14261.html</wfw:comment><comments>http://www.cppblog.com/asp/articles/14261.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/asp/comments/commentRss/14261.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/asp/services/trackbacks/14261.html</trackback:ping><description><![CDATA[
		<font size="2">    用模板写的一个归并排序，并且注明了用归并排序求逆序数的方法……<br /><br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> mergeSort( T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size )<br /><img id="Codehighlighter1_74_123_Open_Image" onclick="this.style.display='none'; Codehighlighter1_74_123_Open_Text.style.display='none'; Codehighlighter1_74_123_Closed_Image.style.display='inline'; Codehighlighter1_74_123_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_74_123_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_74_123_Closed_Text.style.display='none'; Codehighlighter1_74_123_Open_Image.style.display='inline'; Codehighlighter1_74_123_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_74_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" /></span><span id="Codehighlighter1_74_123_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> T[size];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    mergePass(a,b,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,size</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/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> mergePass( T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a, T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> r )<br /><img id="Codehighlighter1_190_311_Open_Image" onclick="this.style.display='none'; Codehighlighter1_190_311_Open_Text.style.display='none'; Codehighlighter1_190_311_Closed_Image.style.display='inline'; Codehighlighter1_190_311_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_190_311_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_190_311_Closed_Text.style.display='none'; Codehighlighter1_190_311_Open_Image.style.display='inline'; Codehighlighter1_190_311_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_190_311_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" /></span><span id="Codehighlighter1_190_311_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> m;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(l</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">r)<br /><img id="Codehighlighter1_210_309_Open_Image" onclick="this.style.display='none'; Codehighlighter1_210_309_Open_Text.style.display='none'; Codehighlighter1_210_309_Closed_Image.style.display='inline'; Codehighlighter1_210_309_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_210_309_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_210_309_Closed_Text.style.display='none'; Codehighlighter1_210_309_Open_Image.style.display='inline'; Codehighlighter1_210_309_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_210_309_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" /></span><span id="Codehighlighter1_210_309_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        m</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(l</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">r)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        mergePass(a,b,l,m);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        mergePass(a,b,m</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        merge(a,b,l,m,r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        copy(a,b,l,r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> merge( T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a, T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> m, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> r )<br /><img id="Codehighlighter1_381_625_Open_Image" onclick="this.style.display='none'; Codehighlighter1_381_625_Open_Text.style.display='none'; Codehighlighter1_381_625_Closed_Image.style.display='inline'; Codehighlighter1_381_625_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_381_625_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_381_625_Closed_Text.style.display='none'; Codehighlighter1_381_625_Open_Image.style.display='inline'; Codehighlighter1_381_625_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_381_625_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" /></span><span id="Codehighlighter1_381_625_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">l,j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m</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" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">r)<br /><img id="Codehighlighter1_419_563_Open_Image" onclick="this.style.display='none'; Codehighlighter1_419_563_Open_Text.style.display='none'; Codehighlighter1_419_563_Closed_Image.style.display='inline'; Codehighlighter1_419_563_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_419_563_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_419_563_Closed_Text.style.display='none'; Codehighlighter1_419_563_Open_Image.style.display='inline'; Codehighlighter1_419_563_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_419_563_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" /></span><span id="Codehighlighter1_419_563_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a[i]</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b[j])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            b[l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_465_560_Open_Image" onclick="this.style.display='none'; Codehighlighter1_465_560_Open_Text.style.display='none'; Codehighlighter1_465_560_Closed_Image.style.display='inline'; Codehighlighter1_465_560_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_465_560_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_465_560_Closed_Text.style.display='none'; Codehighlighter1_465_560_Open_Image.style.display='inline'; Codehighlighter1_465_560_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_465_560_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" /></span><span id="Codehighlighter1_465_560_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            b[l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">num+=m-i+1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">用归并排序求逆序数则在这里添加这句话，num为全局变量<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">num+=前路还没有归并的长度+1</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">m)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        b[l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">r)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        b[l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> copy( T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a, T </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> r )<br /><img id="Codehighlighter1_687_728_Open_Image" onclick="this.style.display='none'; Codehighlighter1_687_728_Open_Text.style.display='none'; Codehighlighter1_687_728_Closed_Image.style.display='inline'; Codehighlighter1_687_728_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_687_728_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_687_728_Closed_Text.style.display='none'; Codehighlighter1_687_728_Open_Image.style.display='inline'; Codehighlighter1_687_728_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_687_728_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" /></span><span id="Codehighlighter1_687_728_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(l</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">r)<br /><img id="Codehighlighter1_703_726_Open_Image" onclick="this.style.display='none'; Codehighlighter1_703_726_Open_Text.style.display='none'; Codehighlighter1_703_726_Closed_Image.style.display='inline'; Codehighlighter1_703_726_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_703_726_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_703_726_Closed_Text.style.display='none'; Codehighlighter1_703_726_Open_Image.style.display='inline'; Codehighlighter1_703_726_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_703_726_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" /></span><span id="Codehighlighter1_703_726_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        a[l]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">b[l];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_742_868_Open_Image" onclick="this.style.display='none'; Codehighlighter1_742_868_Open_Text.style.display='none'; Codehighlighter1_742_868_Closed_Image.style.display='inline'; Codehighlighter1_742_868_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_742_868_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_742_868_Closed_Text.style.display='none'; Codehighlighter1_742_868_Open_Image.style.display='inline'; Codehighlighter1_742_868_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_742_868_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" /></span><span id="Codehighlighter1_742_868_Open_Text"><span style="COLOR: #000000">{<br /><img id="Codehighlighter1_755_776_Open_Image" onclick="this.style.display='none'; Codehighlighter1_755_776_Open_Text.style.display='none'; Codehighlighter1_755_776_Closed_Image.style.display='inline'; Codehighlighter1_755_776_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_755_776_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_755_776_Closed_Text.style.display='none'; Codehighlighter1_755_776_Open_Image.style.display='inline'; Codehighlighter1_755_776_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id="Codehighlighter1_755_776_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" /></span><span id="Codehighlighter1_755_776_Open_Text"><span style="COLOR: #000000">{</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">,i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    mergeSort(a,</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(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">10</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,a[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    putchar(</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" />    </span><span style="COLOR: #0000ff">return</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/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/asp/aggbug/14261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/asp/" target="_blank">Asp</a> 2006-10-26 23:01 <a href="http://www.cppblog.com/asp/articles/14261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>中值表达式的计值</title><link>http://www.cppblog.com/asp/articles/14145.html</link><dc:creator>Asp</dc:creator><author>Asp</author><pubDate>Wed, 25 Oct 2006 12:10:00 GMT</pubDate><guid>http://www.cppblog.com/asp/articles/14145.html</guid><wfw:comment>http://www.cppblog.com/asp/comments/14145.html</wfw:comment><comments>http://www.cppblog.com/asp/articles/14145.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/asp/comments/commentRss/14145.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/asp/services/trackbacks/14145.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 用double写的中值表达式的计值，可以算小数的……																/*Sample Test Cases*/										/*																						test case:2*(3+4)-8/22*(3.25+4.75)-8/2(2*3+(2+5*2-10))/(8/2)15+10*(50*2-5)/215+10*(...&nbsp;&nbsp;<a href='http://www.cppblog.com/asp/articles/14145.html'>阅读全文</a><img src ="http://www.cppblog.com/asp/aggbug/14145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/asp/" target="_blank">Asp</a> 2006-10-25 20:10 <a href="http://www.cppblog.com/asp/articles/14145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>