<?xml version="1.0" encoding="gb2312"?>

<!-- RSS generated by oioj.net on 4/16/2004 ; 感谢LeXRus提供 RSS 2.0 文档; 此文件可自由使用，但请保留此行信息 --> 
<!-- Source download URL: http://blogger.org.cn/blog/rss2.asp       -->
<rss version="2.0">

<channel>
<title>ShM1|y_sun的博客</title>
<link>http://blogger.org.cn/blog/blog.asp?name=ShM1|y_sun</link>
<description>ShM1|y_sun的博客</description>
<copyright>blogger.org.cn</copyright>
<generator>W3CHINA Blog</generator>
<webMaster>webmaster@blogger.org.cn</webMaster>
<item>
<title><![CDATA[有几天没来了]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16722</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/18 15:35:18</pubDate>
<description><![CDATA[有几天没来,这几天比较忙,还是累,真累,男人流血不喊累啊!给我顶住,哎,写了有几天了,就是没人留言,哎郁闷了,看贴不回,不是男人做的事情啊!]]></description>
</item><item>
<title><![CDATA[男人容易吗?]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16488</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/11 10:58:26</pubDate>
<description><![CDATA[
<P>男人容易吗?读了20年的书,每个月拿那点小钱,自己到现在还很难以养活自己,每天在公交上的时间就要4个小时,才2个月,不仅仅是身体的疲劳,心理上的疲劳也逐渐闲现,今天上班一点精神也打不起来,听起来了" 少年壮志不言愁" ,"男儿当自强" ,希望能给我增加能量,生活添加激情,没有激情的工作着,多少都是被生活主宰着我,我要去主宰生活,积极的面对.从现在开始.保持最年轻的心,勇敢的走下去.</P>
<P><A href="http://www.ting88.com/htm/3958s23.htm">http://www.ting88.com/htm/3958s23.htm</A></P>
<P><FONT color=#0000ff>《男儿当自强&nbsp;-&nbsp;林子祥》</FONT>歌词： <BR></P>
<DIV align=right><A onclick="OpenLrc('3958_23',2)" href="http://www.ting88.com/htm/3958s23.htm#">添加歌词</A>　<A onclick="OpenLrc('3958_23',1)" href="http://www.ting88.com/htm/3958s23.htm#">歌词报错</A></DIV>
<P><BR><BR>&nbsp;</P>
<DIV id=LRC style="OVERFLOW: auto; WIDTH: 240px; HEIGHT: 230px" align=center>傲气傲笑万重浪 热血热胜红日光 <BR>胆似铁打 骨似精钢 胸襟百千丈 <BR>眼光万里长 誓发自强 做好汉 <BR>做个好汉子 每天要自强 <BR>热血男子热胜红日光 让海天为我聚能量 <BR>去开天劈地 为我理想去闯 看碧波高壮 <BR>又看碧空广阔浩气扬 既是男儿当自强 <BR>昂步挺胸大家作栋梁 做好汉 用我百点热 <BR>耀出千分光 做个好汉子 热血热肠热 热胜红日光</FONT><BR></DIV>]]></description>
</item><item>
<title><![CDATA[关于程序员的一些说法]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16359</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/7 9:14:51</pubDate>
<description><![CDATA[
<P>如果你已经是个老程序员的话,那我就没的说了,如果你是个新手,没做过20个项目以上的都是新手,我也是,学习c++,最重要的就是在做项目的过程中体会,c++的奥妙,掌握它的精髓.光看书,是不能解决实际问题的,实际问题的解决往往和书本上的介绍有很大的出入,而且也跟不上时代的步伐.只有多做项目,多思考,就会很快的进步,4个月正真的掌握c++是没的问题的@</P>
<P>好在我是搞硬件的,不过我们研究所里的程序员都是高手,让我对写程序也产生了兴趣,我争取3,4月出师,而且c/c++程序员比较难培养,所以工作比较好找,c语言之父"&nbsp;&nbsp; ,,,,..."说过,他只所以发明c语言就是为了,不让程序员的身价下降的太快,所以才写出了这么个难懂的语言.</P>]]></description>
</item><item>
<title><![CDATA[算法定义]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16330</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 13:09:32</pubDate>
<description><![CDATA[<BR>算法是在有限步骤内求解某一问题所使用的一组定义明确的规则。通俗点说，就是计算机解题的过程。在这个过程中，无论是形成解题思路还是编写程序，都是在实施某种算法。前者是推理实现的算法，后者是操作实现的算法。<BR><BR>一个算法应该具有以下五个重要的特征： <BR><BR>有穷性： 一个算法必须保证执行有限步之后结束； <BR>确切性： 算法的每一步骤必须有确切的定义； <BR>输入：一个算法有0个或多个输入，以刻画运算对象的初始情况，所谓0个输入是指算法本身定除了初始条件； <BR>输出：一个算法有一个或多个输出，以反映对输入数据加工后的结果。没有输出的算法是毫无意义的； <BR>可行性： 算法原则上能够精确地运行，而且人们用笔和纸做有限次运算后即可完成。 <BR>　<BR><BR>Did you know <BR>Algorithm 一词的由来 <BR><BR>Algorithm(算法)一词本身就十分有趣。初看起来，这个词好像是某人打算要写“Logarithm”(对数)一词但却把头四个字母写的前后颠倒了。这个词一直到1957年之前在Webster's New World Dictionary(《韦氏新世界词典》)中还未出现，我们只能找到带有它的古代涵义的较老形式的“Algorism”(算术)，指的是用阿拉伯数字进行算术运算的过程。在中世纪时，珠算家用算盘进行计算，而算术家用算术进行计算。中世纪之后，对这个词的起源已经拿不准了，早期的语言学家试图推断它的来历，认为它是从把algiros(费力的)+arithmos(数字)组合起来派生而成的，但另一些人则不同意这种说法，认为这个词是从“喀斯迪尔国王Algor”派生而来的。最后，数学史学家发现了algorism(算术)一词的真实起源：它来源于著名的Persian Textbook(《波斯教科书》)的作者的名字Abu Ja'far Mohammed ibn M&amp;ucirc;s&amp;acirc; al-Khow&amp;acirc;rizm （约公元前825年）——从字面上看，这个名字的意思是“Ja'far 的父亲，Mohammed 和 M&amp;ucirc;s&amp;acirc; 的儿子，Khow&amp;acirc;rizm 的本地人”。Khow&amp;acirc;rizm 是前苏联XИBA(基发) 的小城镇 。Al-Khow&amp;acirc;rizm 写了著名的书Kitab al jabr w'al-muqabala (《复原和化简的规则》)；另一个词，“algebra”(代数)，是从他的书的标题引出来的，尽管这本书实际上根本不是讲代数的。<BR><BR>逐渐地，“algorism”的形式和意义就变得面目全非了。如牛津英语字典所说明的，这个词是由于同arithmetic(算术)相混淆而形成的错拼词。由algorism又变成algorithm。一本早期的德文数学词典 Vollstandiges Mathematisches Lexicon (《数学大全辞典》) ，给出了Algorithmus (算法)一词的如下定义：“在这个名称之下，组合了四种类型的算术计算的概念，即加法、乘法、减法、除法”。拉顶短语algorithmus infinitesimalis (无限小方法) ，在当时就用来表示Leibnitz(莱布尼兹)所发明的以无限小量进行计算的微积分方法。<BR><BR>1950年左右，algorithm一词经常地同欧几里德算法(Euclid's algorithm)联系在一起。这个算法就是在欧几里德的《几何原本》(Euclid's Elements ,第VII卷，命题i和ii)中所阐述的求两个数的最大公约数的过程(即辗转相除法)。]]></description>
</item><item>
<title><![CDATA[C++程序设计最佳实践]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16329</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 13:04:04</pubDate>
<description><![CDATA[随着计算机语言的发展，我们现在编写一个程序越来越容易了。利用一些软件开发工具，往往只要通过鼠标的拖拖点点，计算机就会自动帮你生成许多代码。但在很多时候，计算机的这种能力被滥用了，我们往往只考虑把这个程序搭起来，而不去考虑程序的性能如何，程序是否足够的健壮。而此节课的目的主要是介绍一些编码的经验，让大家编写的程序更加健壮和高性能。<BR><BR>　　1、Prefer const and inline to #define <BR><BR>　　在C++编程中应该尽量使用const和inline来代替#define，尽量做到能不用#define就不用。#define常见的用途有“定义常量”以及“定义宏”，但其中存在诸多的弊病。 <BR><BR>　　第一，查错不直观，不利于调试。Define的定义是由预处理程序处理的，作的是完全的文本替换，不做任何的类型检查。在编译器处理阶段，define定义的东西已经被完全替换了，这样在debug的时候就看不到任何的相关信息，即跟踪时不能step into宏。例如，把ASPECT_RATIO用define定义成1.653，编译器就看不到ASPECT_RATIO这个名字了。如果编译器报1.653错，那么就无从知道此1.653来自于何处。在真正编码的时候应该使用如下的语句来定义：<BR><BR><BR>static const double ASPECT_RATIO = 1.653;<BR><BR>　　第二，没有任何类型信息，不是type safe。因为它是文本级别的替换，这样不利于程序的维护。<BR><BR>　　第三，define的使用很容易造成污染。比如，如果有两个头文件都定义了ASPECT_RATIO, 而一个CPP文件又同时包含了这两个头文件，那么就会造成冲突。更难查的是另外一种错误，比如有如下的代码：<BR>　　// in header file def.h<BR>　　#define Apple 1<BR>　　#define Orange 2<BR>　　　 #define Pineapple 3 <BR>　　 …<BR>　　// in some cpp file that includes the def.h<BR>　　enum Colors {White, Black, Purple, Orange};<BR><BR>　　在.h文件中Orange被定义成水果的一种，而在.cpp文件中Orange又成为了一种颜色，那么编译器就会把此处的Orange替换成2，编译可能仍然可以通过，程序也能够运行，但是这就成了一个bug，表现出古怪的错误，且很难查错。再比如定义了一个求a与b哪个数大的宏，#define max(a,b) ((a) &gt; (b) ? (a) : (b))<BR>　　int a = 5, b = 0; <BR>　　max(++ a, b); <BR>　　max(++ a, b + 10);<BR><BR>　　在上面的操作中，max(++ a, b); 语句中a被++了两次，而max(++ a, b + 10); 语句中a只加了一次，这样在程序处理中就很有可能成为一个bug，且此bug也非常的难找。在实际编码时可以使用如下的语句来做：<BR>　　template&lt;class T&gt; <BR>　　inline const T&amp; <BR>　　max(const T&amp; a, const T&amp; b) { return a &gt; b ? a : b; }<BR><BR>　　2、Prefer C++-style casts <BR><BR>　　在程序中经常会需要把一种类型转换成另外一种类型，在C++中应该使用static_cast、const_cast、dynamic_cast、reinterpret_cast关键字来做类型转换。因为这有以下好处，一是其本身就是一种注释，在代码中看到上面这些关键字就可马上知道此处是进行类型转换。二是C语言中类型转换通常是很难进行搜索的，而通过关键字cast则可以很容易的找到程序中出现类型转换的地方了。<BR><BR>　　3、Distinguish between prefix and postfix forms of increment and decrement operators <BR><BR>　　通常对于操作系统或编译器自身支持的类型，prefix（前缀，如++i）与postfix（后缀，如i++）的效果是一样的。因为现在的编译器都很聪明，它会自动做优化，这两者的汇编代码是一样的，性能不会有差别。但有时候也会有不同的，如一些重载了操作符的类型。下面是模拟prefix与postfix的操作过程，可以发现在postfix操作中会生成一个临时变量，而这一临时变量是会占用额外的时间和开销的。<BR>　　// prefix form: increment and fetch<BR>　　UPInt&amp; UPInt::operator++() <BR>　　　{ <BR>　　　 *this += 1; // increment <BR>　　　return *this; // fetch <BR>　　　} <BR>　　// postfix form: fetch and increment <BR>　　　const UPInt UPInt::operator++(int) <BR>　　　{<BR>　　　 UPInt oldValue = *this; // fetch<BR>　　　++(*this); // increment <BR>　　　 return oldValue; // return what was fetched<BR>　　 }<BR><BR>　　一般情况下不需要区分是先++，还是后++，但是我们在编写程序的时候最好能习惯性的将其写成++i的形式，如在使用STL中的iterator时，prefix与postfix会有相当大的性能差异。请不要小看这些细节，实际在编写程序的时候，若不注意具体细节，你会发现程序的性能会非常的低。但要注意，虽然在大多数情况下可以用prefix来代替postfix，但有一种情况例外，那就是有[]操作符时，比如gzArray [++index] 是不等于 gzArray[index++]的。<BR><BR>　4、Minimizing Compile-time Dependencies <BR><BR>　　有些人在编写程序时，往往喜欢将一个.h文件包含到另一个.h文件，而实践证明在做大型软件时这是一个非常不好的习惯，因这样会造成很多依赖的问题，包含较多的.h文件，别人又使用了这个class，而在他的那个工程中可能并不存在这些.h文件，这样很可能就编译不能通过。而且这样做，还可能造成很难去更新一个模块的情况。因为一个.h文件被很多模块包含的话，如果修改了此.h文件，在编译系统的时候，编译器会去寻找哪些模块依赖于某个被修改过的.h文件，那么就导致了所有包含入此.h文件的模块全都要进行重新编译。在项目比较小的时候，大家可能还感觉不到差别，但是如果说是在大型的软件系统里，你可能编译一遍源码需要七、八个小时。如果你这个.h文件被很多模块包含的话，就算在.h文件中加了一行注释，在编译时编译器检查哪些文件被改动，那么所有包含入此.h文件的模块都会被重新编译，造成巨大的时间和精力负担。对于此问题，解决的方法就是让.h文件自包含，也就是说让它包含尽量少的东西。所谓尽量少是指如删掉任何一个它包含进来的.h文件，都将无法正常进行工作。其实在很多情况下，并不需要一个.h文件去包含另一个.h文件，完全可以通过class声明来解决依赖关系的这种问题。再来看下面这个例子：<BR>　　#include "a.h" // class A<BR>　　#include "b.h" // class B<BR>　　#include "c.h" // class C<BR>　　#include "d.h" // class D<BR>　　#include "e.h" // class E<BR>　　class X : public A, private B<BR>　　{<BR>　　　public:<BR>　　E SomeFunctionCall(E someParameter); <BR>　　　private:<BR>　　 D m_dInstance;<BR>　　};<BR><BR>　　当类X从类A和类B中派生时，需要知道X在内存中都有哪些data，通常在内存中前面是基类的data，后面紧跟的是此派生类自身定义的data，因此就必须知道类A与类B的内部细节，要不然编译器就无法来安排内存了。但是在处理参数以及参数返回值的时候，实际上并不需要知道这些信息，在此处定义的SomeFunctionCall()只需知道E是个class就足够了，并不需要知道类E中的data如长度等的具体细节。上面的代码应该改写成如下的形式，以减少依赖关系：<BR>　　#include "a.h" // class A<BR>　　#include "b.h" // class B<BR>　　#include "c.h" // class C<BR>　　#include "d.h" // class D<BR>　　class E;<BR>　　class X : public A, private B<BR>　　{<BR>　　　public:<BR>　　E SomeFunctionCall(E someParameter); <BR>　　　private:<BR>　　D m_dInstance;<BR>　　}; <BR><BR>　　5、Never treat arrays polymorphically <BR><BR>　　不要把数组和多态一起使用，请看下面的例子。<BR>　　class BST { ... }; <BR>　　class BalancedBST: public BST { ... }; <BR>　　void printBSTArray(ostream&amp; s, const BST array[], int numElements) <BR>　　{ <BR>　　for (int i = 0; i &lt; numElements; ++i) <BR>　　{ <BR>　　 s &lt;&lt; array[i]; <BR>　　// this assumes an operator&lt;&lt; is defined for BST<BR>　　} <BR>　　}<BR><BR>　　BalancedBST bBSTArray[10]; <BR>　　printBSTArray(cout, bBSTArray, 10); <BR><BR>　　数组在内存中是一个连续的内存空间，而在数组中应该如何来定位一个元素呢？过程是这样的，编译器可以知道每个数据类型的长度大小，如果数组的index是0，则会自动去取第一个元素；如果是指定了某个index，编译器则会根据此index与该数据类型的长度自动去算出该元素的位置。<BR><BR>　　在printBSTArray()函数中，尽管传入的参数是BalancedBST类型，但由于其本来定义的类型是BST，那么它依然会根据BST来计算类型的长度。而通常派生类实例所占的内存要比基类实例所占的内存大一些，因此该程序在编译时会报错。请记住，永远不要把数组和C++的多态性放在一起使用。<BR><BR>　　6、Prevent exceptions from leaving destructors <BR><BR>　　析构函数中一定不要抛出异常。通常有两种情况会导致析构函数的调用，一种是当该类的对象离开了它的域，或delete表达式中一个该类对象的指针，另一种是由于异常而引起析构函数的调用。<BR><BR>　　如果析构函数被调用是由于exception引起，而此时在析构函数中又抛出了异常，程序会立即被系统终止，甚至都来不及进行内存释放。因此如果在析构函数中抛出异常的话，就很容易混淆引起异常的原因，且这样的软件也会让用户非常恼火。由于析构函数中很可能会调用其它的一些函数，所以在写析构函数的时候一定要注意，对这些函数是否会抛出异常要非常清楚，如果会的话，就一定要小心了。比如下面这段代码：<BR>　　Session::~Session() <BR>　 { <BR>　　logDestruction(this);<BR>　 } <BR><BR>　　比如logDestruction()函数可能会抛出异常，那么我们就应该采用下面这种代码的形式： <BR>　　Session::~Session() <BR>　 { <BR>　　 try <BR>　　{<BR>　　　logDestruction(this); <BR>　　 }<BR>　　 catch (...) <BR>　　{ <BR>　　 } <BR>　} <BR><BR>　　这样程序出错的时候不会被立即关掉，可以给用户一些其它的选择，至少先让他把目前在做的工作保存下来。<BR><BR>　　7、Optimization:Remember the 80-20 rule <BR><BR>　　在软件界有一个20-80法则，其实这是一个很有趣的现象，比如一个程序中20%的代码使用了该程序所占资源的80%；一个程序中20%的代码占用了总运行时间的80%；一个程序中20%的代码使用了该程序所占内存的80%；在20%的代码上面需要花费80%的维护力量，等等。这个规律还可以被继续推广下去，不过这个规律无法被证明，它是人们在实践中观察得出的结果。从这个规律出发，我们在做程序优化的时候，就有了针对性。比如想提高代码的运行速度，根据这个规律可以知道其中20%的代码占用了80%的运行时间，因此我们只要找到这20%的代码，并进行相应的优化，那么我们程序的运行速度就可以有较大的提高。再如有一个函数，占用了程序80%的运行时间，如果把这个函数的执行速度提高10倍，那么对程序整体性能的提高，影响是非常巨大的。如果有一个函数运行时间只占总时间的1%，那就算把这个函数的运行速度提高1000倍，对程序整体性能的提高也是影响不大的。所以我们的基本思想就是找到占用运行时间最大的那个函数，然后去优化它，哪怕只是改进了一点点，程序的整体性能也可以被提高很多。<BR><BR>　　要想找出那20%的代码，我们的方法就是使用Profiler，它实际上是一些公司所开发的工具，可以检查程序中各个模块所分配内存的使用情况，以及每个函数所运行的时间等。常见的Profiler有Intel公司开发的VTune，微软公司开发的Visual Studio profiler，DevPartner from Compuware等。]]></description>
</item><item>
<title><![CDATA[上海小记]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16328</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 12:41:05</pubDate>
<description><![CDATA[<P>来上海也有2个月了;接触了很多的人,工作的,没工作的,能挣钱的,能花钱的,</P>
<P>第一份工作,对刚毕业的学生很重要,虽然社会很为难刚毕业的学生,一方面,社会需要大量的有经验的人才,一方面学生最缺的是经验,理论其实也不扎实.供求总是不平衡的.第一份工作,往往能给你在职业生涯提供很多的思考余地.要公司给你机会,要你自己抓住机会.我的一个朋友,他们单位做的事情没什么技术含量,而且钱也有2000多,很松的,每天都是在看网页中度过.可是现在单位不景气了,人走了,现在是找不到好工作,一直再犹豫是不是要离开上海.工作不一定要好,不一定要给你很多钱,但是你一定要能学到技术,确定自己的目标.努力才是硬道理.</P>
<P>来上海就是来挣钱的,不然来做什么呢,还有就是花钱,老话是不会花钱,不会挣钱,</P>
<P>我的话也只是针对那些搞技术的了,如果搞的是商业的,那就多接触人,接触接触再接触,.....</P>
<P>人在上海都不容易,什么都是为了钱,真的,不然你来上海,做什么???</P>
<P>&nbsp;</P>]]></description>
</item><item>
<title><![CDATA[九钟排序原码（九）　堆排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16326</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:13:24</pubDate>
<description><![CDATA[
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::HeapSort(int*list,int num)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(int i=(num-2)/2;i&gt;=0;i--)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FiltDown(list,i,num-1);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(i=num-1;i&gt;=1;i--)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temps=list[0];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list[0]=list[i];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list[i]=temps;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FiltDown(list,0,i-1);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">//<SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(m_mark==1)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">//<SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>show(list);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::FiltDown(int*list,int i,int end)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int c=i;int ch=2*i+1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temp=list[i];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while(ch&lt;=end)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(ch&lt;end&amp;&amp;list[ch]&lt;list[ch+1])<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ch++;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(temp&gt;=list[ch])break;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>else<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list[c]=list[ch];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>c=ch;ch=2*ch+1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list[c]=temp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>]]></description>
</item><item>
<title><![CDATA[九钟排序原码（八）　快速排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16325</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:12:36</pubDate>
<description><![CDATA[<A>　
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::quick_sort(int x[], int low, int high)<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">快速排序函数的实现过程</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{ <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int pivotkey;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(low&lt;high)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>pivotkey=partition(x,low,high);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>quick_sort(x,low,pivotkey-1);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>quick_sort(x,pivotkey+1,high);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">} <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">int CSortDlg::partition(int x[],int low,int high)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>int pivotkey;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>pivotkey=x[low];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>while(low&lt;high)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while(low&lt;high&amp;&amp;x[high]&gt;pivotkey)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>--high;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[low]=x[high];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while(low&lt;high&amp;&amp;x[low]&lt;pivotkey)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>++low;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[high]=x[low];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>//<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[low]=x[0];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>x[low]=pivotkey;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return low;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P></A>]]></description>
</item><item>
<title><![CDATA[九钟排序原码（七）基数排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16324</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:11:19</pubDate>
<description><![CDATA[<A>　
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">int CSortDlg::digit(int data,int n)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int i = -1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int k = 0; k &lt;= n;++k)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>i = data % RADIX;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data = data / RADIX;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return i;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::SortOnDigit(int* data,int d,int left,int right)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int c[RADIX] = {0};<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>//c[i]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记录</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">d</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位上为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的元素个数</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int i = left; i &lt;= right ;i++ )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>++c[digit(data[i],d)];<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记录</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">d</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位上相同的数据个数</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int j = 1;j &lt; RADIX ;++j )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>c[j] += c[j-1];<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">很明显，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">d</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位上较大（就是</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">j</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值），元素越大</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//c[j]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记录</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">d</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位上小于等于</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">j</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的元素的个数</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int len = right - left +1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int* tmp = new int[len];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">知道了有多少元素在</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">d</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位置上比自己小，则可以确定</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">d</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位上的值的元素位置</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int k = right; k &gt;= left; k--)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp[--c[digit(data[k],d)]] = data[k];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int m = left;m &lt;= right ;++m )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data[m] = tmp[m - left];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>delete[] tmp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::RadixSort(int* data,int left,int right)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int i = 0;i &lt; WIDTH; ++i)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>SortOnDigit(data,i,left,right);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P></A>]]></description>
</item><item>
<title><![CDATA[九钟排序原码（六）直接选择排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16323</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:10:23</pubDate>
<description><![CDATA[
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::SelectSort(int x[])<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int i=0;i&lt;9;i++) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>SelectExchange(x,i);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::SelectExchange(int x[],const int i)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int k=i;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int j=i+1;j&lt;10;j++) <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(x[j]&lt;x[k])<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>k=j;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(k!=i)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temp=x[i];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[i]=x[k];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[k]=temp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>]]></description>
</item><item>
<title><![CDATA[九钟排序原码（五）折半插入排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16322</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:08:54</pubDate>
<description><![CDATA[
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::BinaryInsertSort(int x[])<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int i=1;i&lt;10;i++) <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>BinaryInsert(x,i);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::BinaryInsert(int x[],int i)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int left=0,right=i-1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temp=x[i];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (left&lt;=right) //</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">利用折半查找找插入位置</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int middle=(left+right)/2;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">取中点</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (temp&lt;x[middle]) //</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">插入值小于中点值</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>right=middle-1;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">向左缩小区间</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>else<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">否则向右缩小区间</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>left=middle+1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int k=i-1;k&gt;=left;k--)//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">成块移动，空出插入位置</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[k+1]=x[k];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[left]=temp;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">插入</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>]]></description>
</item><item>
<title><![CDATA[九种排序原码（四）归并排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16321</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:07:32</pubDate>
<description><![CDATA[
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::MergeSort(int x[])<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temp_array[10];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int len=1;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (len&lt;10) {<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">归并排序</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MergePass(x,temp_array,len);//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一趟两路归并后归并项长度加倍</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>len*=2;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>MergePass(temp_array,x,len);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>len*=2;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">//<SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>delete[] temp_array;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::MergePass(int init_array[],int merge_array[],const int len)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一趟归并排序</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int i=0;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (i+2*len&lt;=9) {//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对长度为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">len</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的子表两两归并，直到表中剩余元素个数不足</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">2*len</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为止</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>merge(init_array,merge_array,i,i+len-1,i+2*len-1);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>i+=2*len;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (i+len&lt;=9)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>merge(init_array,merge_array,i,i+len-1,9);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>else<SPAN style="mso-tab-count: 6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for (int j=i;j&lt;=9;j++) {//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">若不能做归并，就复制</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>merge_array[j]=init_array[j];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::merge(int init_array[],int merge_array[],const int l,const int m,const int n)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int i=l,j=m+1,k=l;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>while (i&lt;=m&amp;&amp;j&lt;=n) <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>if (init_array[i]&lt;=init_array[j]) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>merge_array[k]=init_array[i];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>i++;k++;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>else<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>merge_array[k]=init_array[j];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>j++;k++;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>if (i&lt;=m) <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>for (int n1=k,n2=i;n1&lt;=n&amp;&amp;n2&lt;=m;n1++,n2++) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>merge_array[n1]=init_array[n2];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>else<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>for (int n1=k, n2=j;n1&lt;=n&amp;&amp;n2&lt;=n;n1++,n2++) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>merge_array[n1]= init_array[n2];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>]]></description>
</item><item>
<title><![CDATA[九种排序原码（三）　希尔排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16320</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:04:50</pubDate>
<description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::Shellsort(int x[])<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int gap=10/2;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">增量的初始值</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (gap)//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">循环条件是</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">gap&gt;=1<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ShellInsert(x,gap);//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按增量</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">gap</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">划分子序列，分别进行插入排序</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>gap=gap==2?1:(int)(gap/2);//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">缩小增量</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">gap<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::ShellInsert(int x[],const int gap)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(int i=gap;i&lt;10;i++)//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">各子序列轮流执行插入排序</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temp=x[i];int j=i;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">暂存待插入对象</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (j&gt;=gap&amp;&amp;temp&lt;x[j-gap]) {//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当前插入元素比位于</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">j-gap</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的元素小，则位于</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">j-gap</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的元</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">素后移</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[j]=x[j-gap];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>j-=gap;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">后移到第</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">j</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个位置，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">j</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指标前指</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[j]=temp;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">插入</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>]]></description>
</item><item>
<title><![CDATA[九种排序原码(二) 直接插入排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16319</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 11:01:33</pubDate>
<description><![CDATA[<SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::InsertionSort(int x[])<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN> 
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(int i=1;i&lt;10;i++)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Insert(x,i);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::Insert(int x[],int i)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int temp=x[i]; int j=i;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (j&gt;0&amp;&amp;temp&lt;x[j-1]) <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[j]=x[j-1];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>j--;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[j]=temp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>]]></description>
</item><item>
<title><![CDATA[九种排序原码( 一) 冒泡排序]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16318</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 10:59:13</pubDate>
<description><![CDATA[<A></A>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::bubble_sort(int x[]){<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">对数组</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">x[]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">逐趟进行比较</SPAN><SPAN style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，遇到逆序即交换</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int i =1;int exchange=1;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">当</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">exchange</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">0</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">时，则停止排序</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while((i&lt;10 )&amp;&amp;exchange){//<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>BubbleExchange( x, i, exchange);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>i++;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">void CSortDlg::BubbleExchange(int x[],int i,int exchange){<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>exchange = 0;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">假定元素未交换</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(int j =9;j&gt;=i;j--){<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if(x[j-1]&gt;x[j])//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">发生了逆序</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>temp = x[j-1];//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">交换</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[j-1]=x[j];<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x[j] = temp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>exchange = 1;//</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">做“发生了交换”的标志</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">}<o:p></o:p></FONT></SPAN></P>]]></description>
</item><item>
<title><![CDATA[关于排序的认识]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16309</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 9:16:26</pubDate>
<description><![CDATA[<A></A>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">排序总的可以分为<SPAN style="COLOR: red">插入排序</SPAN>，<SPAN style="COLOR: red">交换排序</SPAN>，<SPAN style="COLOR: red">选择排序</SPAN>，<SPAN style="COLOR: red">归并排序</SPAN>，<SPAN style="COLOR: red">基数排序</SPAN>等。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">其中<SPAN style="COLOR: red">插入排序</SPAN>又可以细分为<SPAN style="COLOR: blue">直接插入排序</SPAN>，<SPAN style="COLOR: blue">折半排序</SPAN>，<SPAN style="COLOR: blue">希尔排序</SPAN>。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">直接排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的基本思想是：当插入第</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">i </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">（</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">i&gt;=1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">）个对象时，前面的</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[0]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">…….v[i-1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">已经排好序，这时，用</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[i]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的关键码与</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[i-1],v[i-2]……</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的关键码顺序进行比较，找到插入位置即将</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[i]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">插入，原来位置上的对象向后顺移。<SPAN style="COLOR: blue">直接插入排序</SPAN>的时间复杂度为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n2,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">直接插入排序是一种稳定的排序方法。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">折半排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的基本思想是：设在顺序表中有一个对象序列</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[0]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">….v[n-1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，其中，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[0]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">….v[i-1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">是已经排好序的对象。在插入</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[i]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">时，利用折半查找法寻找</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[i]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的插入位置。折半插入是一种稳定的排序方法。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">希尔排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">：当待排序的数列很长时，（即</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">很大时），关键码平均比较次数和对象平均移动次数大约在</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n1.25</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">（即</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">1.25</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">次方，以下同样）到</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">1.6n1.25</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">范围内。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">交换排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">又可细分为<SPAN style="COLOR: blue">冒泡排序</SPAN>，<SPAN style="COLOR: blue">快速排序</SPAN>。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">冒泡排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的基本思想是：设待排序的数列的大小为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，首先比较</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-2]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">和</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的大小，如果</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-2]&gt;v[n-1],</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">则交换</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-2]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">和</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，然后对</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-2]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">和</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[n-3]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">作相同的处理，如此处理，</SPAN><SPAN style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">直到处理完</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[0]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">和</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">v[1],</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">这个称为一趟冒泡，所以只要经过</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n-1 </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">趟冒泡就可以排好所有对象。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman">&nbsp;&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">在最坏情况下总的关键码比较次数为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">0.5n(n-1),</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">对象移动次数为</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">1.5n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">（</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">n-1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">）</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">快速排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的基本思想是：取待排序的数列的某个对象（例如第一个对象）作为基准，将对象分为左右两个数列，左边的全都小于基准，右边的全都大于基准，然后对左右两个树列重复以上操作，直到全部完成。它是一种不稳定的方法，对于待排序的数列很大时，快速排序的确很快，但当待排序的数列很小时，它往往比其它简单的排序方法还要慢。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">选择排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">又可以细分为<SPAN style="COLOR: blue">直接选择排序</SPAN>，<SPAN style="COLOR: blue">堆排序</SPAN>。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">直接选择排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的最坏情况是每一趟都要进行交换，总的对象移动次数是</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">3(n-1)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: blue; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">堆排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">可以分为两个步骤：首先，根据初始输入数据，利用堆的调整算法</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">FilterDown()</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">形成初始堆，</SPAN><SPAN style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">第二步通过一系列的对象交换和重新调整堆进行排序。堆排序的是一个不稳定的排序方法，并且当待排序的数列很大时，堆排序不可取。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">归并排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">就是将两个或两个以上的有序表合并成一个新的有序表。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">基数排序</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的基本思想是：待排序的对象按</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">m</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">个关键码</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">key[0],…..key[m-1]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">排序，每个对象的关键码域用一个数组</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">key[m]</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">表示，对各关键码的排序采用箱排序。</SPAN><SPAN lang=EN-US style="COLOR: red; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">从上面可以得出结论（本人观点），当待排序的数列很小时，可以采取<SPAN style="COLOR: #003366">直接插入排序，折半排序，希尔排序，直接选择排序，堆排序，归并排序，基数排序</SPAN>等众多排序方法，但当待排序的数列很大时，采用<SPAN style="COLOR: #ff6600">快速排序</SPAN>为优。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN lang=EN-US style="COLOR: #333399; mso-bidi-font-size: 10.5pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 1.25pt 0pt -8.9pt; TEXT-INDENT: 31.5pt; mso-char-indent-count: 3.0; mso-para-margin-top: 0cm; mso-para-margin-right: .12gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: -.85gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">就平均性能而言，我认为<SPAN style="COLOR: #ff6600">快速排序</SPAN>最好。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P>]]></description>
</item><item>
<title><![CDATA[大西洋月刊》：我们将如何与中国作战]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16308</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/6 9:05:31</pubDate>
<description><![CDATA[<A><FONT size=1>　</FONT></A><A><FONT size=1>　</FONT></A><FONT size=1>《大西洋月刊》2005年6月号<BR><BR>罗伯特·D·卡普兰<BR><BR>岳健勇&nbsp;陈漫&nbsp;&nbsp;译<BR>
<HR>
<BR>&nbsp;<BR><BR>中东不过只是雷达屏幕上的一个光点，而美国与中国在太平洋的军事竞赛将成为二十一世纪的特点，中国将比过去的俄国更难对付。<BR><BR>一段时间以来，没有任何国家的海军或空军对美国构成威胁，我们的主要竞争对手是陆军，无论是常规力量还是游击队这类反叛力量。这种情况不久将发生变化，中国海军正蓄势待发，准备深入太平洋，那时，它将很快与不愿意从亚洲沿海大陆架后退的美国海空军迎头相撞。不难想象出以下结果：过去数十年的冷战将重演，世界的重心将不在欧洲的心脏，而是在太平洋的环礁（此处上一次为人瞩目是在二战时期，美国海军陆战队曾在此发起猛攻）。在未来的几十年，中国将会利用其漫长的海岸线以及可以延伸到远至中亚的后方基地，在太平洋地区反反复复地与我们玩不对称的游戏，中国最终将能够从其沿海和内地向太平洋里的移动舰船精确发射导弹。<BR><BR>在任何海上交战中，中国将拥有对美国明显的优势，尽管中国在军事技术实力上还比较落后。首先，中国有距离近的优势，中国军队是这场竞赛中废寝忘食的学生，并且学习得很快，它的“软”力量在渐增，这体现了它的某种非凡的适应能力。当无国家的恐怖主义分子填补安全真空的时候，中国则在填补经济真空，环顾全球，在那些像大洋洲陷入困境的太平洋岛国、巴拿马运河区以及偏远的非洲国家这样的不大相关的地区，中国人正在通过建立商业社区和外交前哨、谈判建筑工程及贸易协定等方式，间接地成为当地的主人。搏动着消费和好斗的能量、自恃其大部分农民不是文盲（与历史上其他国家不同）的中国，对美国的自由帝国构成了主要的常规性威胁。<BR><BR>美国应当如何应对在太平洋地区的挑战呢？为了搞清楚此次将发生在中美之间、可能延续好几代人的第二次冷战的动因，有必要了解有关第一次冷战，以及为那次冷战而设立的机构——北大西洋公约组织当前所面临困境的若干情况。这是事关军事战略和战术的问题，带有一些反直观的变化和发展。<BR><BR>首先需要了解的是，二十世纪后半叶的同盟体系已经死亡。在一个需要轻型化及致命性打击的时代，由北约这种委员会机构来指挥作战已变得效率低下，发生在1999年的科索沃战斗，是在欧美关系和谐时期进行的一场针对一个“没了牙齿”的敌人的有限的空中战役，换句话说，这一仗本该打得很顺。但是，在这个当时由19国组成的同盟内部还是产生了裂隙。美国入侵阿富汗使北约组织实际上寿终正寝了，此后，尽管还在谈论什么基础广泛的联盟，欧洲军队不过是在已被美国士兵和陆战队平定的地区做些巡逻及开进驻扎之类的事，这更多地让人联想到了联合国的职责。今天的北约是美国和前共产党国家扩大双边训练的一个媒介，如在保加利亚和罗马尼亚的美国海军陆战队、在波兰和捷克共和国的美国陆军，以及在格鲁吉亚的美国特种部队等等。北约的主体已变成了一个为一流竞赛联盟盟主的美军提供服务的农场系统。<BR><BR>需要了解的第二件事是，北约在太平洋地区的功能性替代物已经存在，并且发展良好，这就是美国太平洋司令部，即PACOM。不受外交官僚机构干扰的太平洋司令部是个庞大但灵巧的结构体，它的领导人很了解新闻界和政策当局里的许多人都不了解的东西，那就是：美国战略关注的重心已经在太平洋，而不是中东。PACOM很快就会和CENTCOM（美国中央司令部）一样家喻户晓，当前中央司令部因中东地区的冲突而闻名，对于美国军方而言，在布什政府的第二任期内，中央司令部的时代将开始消逝。<BR><BR>需要了解的第三件事是，北约自身（大西洋联盟）的活力可以通过太平洋冷战来激发，这是具有讽刺意味的。北约再次成为不可替代的作战工具应当是美国不可动摇的目标。在对华态势中，美国将寻求欧洲和北约的帮助作为战略牵制，同时作为一支力量巡航于比地中海和北大西洋更远的海域。这就是为什么现任北约司令官——海军陆战队上将詹姆斯·琼斯强调，北约的未来在于两栖远征作战。<BR><BR>现在来描述一下我们在太平洋的军事组织。在过去的三年里，我曾多次到过这一地区。太平洋司令部一直是美军最大、历史最久远和最有意思的地区司令部（它起源于1899-1902年打菲律宾战争的美国太平洋陆军）。它所覆盖的地域从东非一直延伸到国际日期变更线以东（包括整个环太平洋地带），囊括了世界陆地面积的一半，以及世界经济总量的半数以上。全世界六大军事力量，包括其中军事现代化速度最快的美国和中国，都活动于美国太平洋司令部的控制范围之内。太平洋司令部除了拥有数量众多的战舰和潜艇外，还有比中央司令部多得多的专门化部队。即便现在美军的地区司令部不再以过去那样的方式“拥有”作战部队，这些数据也是说明问题的，因为这些数据表明，美国已经决定把大量作战部队部署在了太平洋，而不是中东，中央司令部实际上是从太平洋司令部借用了部队来作战。<BR><BR>在最近几年，美国军方通过不动声色地与那些彼此间几乎没有订立安全协定的国家谈判达成双边性的安全协定，在火奴鲁鲁（檀香山）的太平洋司令部总部构建了各种类型的太平洋军事联盟。在这里而不是在迪奇里或达沃斯，正在举行着真正有意思的会议，会议的参加者是来自越南、新加坡、泰国、柬埔寨和菲律宾这些国家的军方官员，他们的旅费通常是由太平洋司令部来资助的。<BR><BR>假如欧洲大陆的德意志第二帝国之父奥托·冯·俾斯麦在世，他将会承认这个正在兴起的太平洋体系。2002年，德国评论员约瑟夫·越飞在发表于《国家利益》杂志上的一篇非常有洞察力的文章里意识到了这一点。在文章里，越飞认为，就政治联盟而言，美国越来越像俾斯麦的普鲁士，英国、俄国和奥地利需要普鲁士甚于它们彼此间的相互需要，从而使它们围绕着柏林的“中心”转；美国入侵阿富汗展示了这样一个世界，即美国能够为不同的危机构建起不同的联盟。越飞指出，世界上其他的大国现在需要美国有甚于它们彼此间的相互需要。<BR><BR>不幸的是，美国没能马上利用这一新的权力安排，因为乔治·W·布什总统缺乏俾斯麦的精细和相应的自制。俾斯麦深知，这样一个体系只有在中心国家不去压倒它的时候才能够持久。布什政府在入侵伊拉克问题上的做法却恰恰是要去压倒这个体系，从而招致了法国、德国、俄罗斯和中国以及一些次要的国家如土耳其、墨西哥和智利联合起来反对我们。<BR><BR>不过，在太平洋地区，俾斯麦式的权力安排还在发育成长，这得益于我们在夏威夷的军官们的务实态度、以及在地理上与华盛顿的意识形态温室相隔五个时区的相对超脱。事实上，太平洋司令部代表着比布什政府入侵伊拉克之前所构建的要纯粹得多的俾斯麦式的帝国上层结构。正如亨利·基辛格在《大外交》（1994年）一书中所写的，俾斯麦不受意识形态的束缚，从看似孤立的一个点出发，在各个方向上建立起了同盟关系。正是认识到了当权力关系被正确“校准”时，战争是可以避免的，俾斯麦给中欧带来了和平和繁荣。<BR><BR>中国重新崛起成为世界大国是不可避免的，我们只有采取类似的务实的办法，才能使我们适应中国的再次崛起；反之，就只有把二十一世纪的地球变成战场。无论何时，大国在崛起或重新崛起时（最近的两个例子是二十世纪初的德国和日本），都会变得格外咄咄逼人，从而把世界投入到剧烈的动荡之中。中国也不会例外！中国现在正在大力建造柴油动力潜艇和核潜艇，这清楚地表明他们不但力图保护自己的沿海大陆架，而且还试图把势力范围扩张到太平洋深处以及太平洋以外的地区。<BR><BR>这完全是正当的。确实地说，中国的统治者不是民主主义者，但他们正在为13亿人民中的许多人谋求解放了的第一世界的生活方式，这就需要保护运送来自中东及其他地区的能源资源的海上通道。自然，他们不会相信美国和印度会为中国人提供这种保护。考虑到此一利害关系，以及大国在追求各自的正当利益时发生冲突的历史教训，美中之间有可能在二十一世纪爆发决定性的军事冲突：假如不是与中国的一场大的战争，那就是一连串的冷战式的延续几年或数十年的对峙。所以这一切大多将发生在太平洋司令部所负责的地区范围之内。<BR><BR>要履行好职责，军事长官们必须以一种尽可能谨慎、巧妙和实用的方式靠近权力，评估或重新评估地区力量的平衡，而把政治方程式中的价值信念问题交给文官们来解决。这样就使得军事长官们在所有的职业政府官僚中，最能避免被自由派的国际主义或新保守派的干涉主义的狂热领入歧途。<BR><BR>二战的历史证明了这种方法的重要性。在20世纪30年代，美国军方对德国和日本力量的增长忧心忡忡，他们正确地对政界进行了游说，加强了我们的军事力量。而到了1940年和1941年，美国军方（与若干年前的德国参谋本部所见略同）有先见性地对两线作战的危险发出了警告；到1944年夏末，美国军方对击败德国已经考虑得很少，而更多地是考虑遏制苏联。今天，美国的空军和海军官员对台湾宣布独立感到担忧，因为这一举动将把美国拖入一场与中国的战争，这不一定符合我们的国家利益。印度尼西亚是另一个例子：太平洋司令部设想，不论印尼军队在人权方面如何糟糕，不接触的政策只会给中国和印尼在这一地区的军事合作敞开大门，而这一地区正是未来世界恐怖主义的天堂，这一假设是正确的。（美军对亚洲海啸做出的反应当然是一种人道主义的努力，但太平洋司令部的战略家们必定已经认识到，积极的反应将会为我们取得军事基地的使用权获得政治上的支持，基地权的获得将成为我们遏制中国战略的组成部分。）或者，设想一下韩国：一些驻扎在太平洋的美国军官对朝鲜半岛的统一抱着想当然的态度，他们主要关注的是，这个国家会不会被中国“芬兰化”，或者，它在美国和日本的势力范围内是否可靠。<BR><BR>太平洋司令部对亚洲权力动态的专注使它拥有不同寻常的外交份量，因而对华盛顿有着更大的影响力。并且，太平洋司令部几乎不会像中央司令部那样受到在华盛顿的美国国内政治的制约。我们在太平洋的行动不会被以色列院外集团那样的团体所左右；新教福音派信徒不会像关心圣地的命运那样去关心环太平洋地带。而且，由于对东亚力量平衡的误判将产生非常严重的经济后果，美国的商业利益和军事利益有可能携手以促成一个经典式的保守的威慑、而不是无端挑衅中国的政策，由此加强太平洋司令部的权威。换句话说，我们对中国以及太平洋的立场是旨在形成某种内在的稳定，进而加强一个“新冷战”的概念，这个“新冷战”将可以持续很长时期。此外，太平洋司令部所控制的诸多政治军事关系的复杂性，将赋予之比现在的中央司令部要大得多的影响力，一些军事专家曾以轻蔑的口气告诉我说，中央司令部只和一群“三流的中东的军队”打交道。<BR><BR>在未来的岁月里，关注焦点从中东到太平洋的相对转移（尽管这是个理想主义的说辞），将迫使下一任美国总统，无论他或她来自哪个政党，都必须实行与温和派共和党总统（如乔治·H·W·布什、杰拉德·福特和理查德·尼克松）类似的外交政策。管理风险将成为指导性思想。即使伊拉克最终成为民主成功的范例，这也无疑属于险胜之胜，军方和外交界无人愿意再次冒险，尤其是在亚洲，贸然在军事上冒险对经济产生的影响将是巨大的。“和中国打起仗来是容易的”，曾经作为在20世纪80年代，为阿富汗抵抗运动设计武器战略的美国中央情报局官员的前特种部队队员、现供职于在华盛顿的战略与预算评估中心的迈克尔·伏克尔指出，“你会看到有多种方案，不单单只涉及台湾——特别是当中国人具备了在整个太平洋地区发动潜艇和导弹攻击能力的时候。但难点在于，如何结束与中国的战争呢？”<BR><BR>像那些卷入第一次世界大战的国家一样，二十一世纪的美国和中国（与人人都密切注视的那些流氓国家不同）都有持久作战的能力，即便其中一方在一场大的战斗或导弹交锋中失利。这将产生深远的影响。伏克尔说，“和中国结束战争可能意味着实行某种形式的政权更迭，因为我们不希望让某个被打伤的、愤怒的政权还留在台上”。另一位五角大楼的分析家对我说，“要结束与中国的战争，就必须大大削弱他们的军事能力，从而威胁他们能源的来源以及共产党对权力的控制。此后的世界将不会和现在一样。这是一条非常危险的路。”<BR><BR>对于太平洋司令部来说，更好的选择是采用俾斯麦的方式，从相对孤立的地理中心—夏威夷群岛—以轮幅状延伸至主要的盟国，如日本、韩国、泰国、新加坡、澳大利亚、新西兰、以及印度—以威慑中国。这些盟国转而将组成次级中心，帮助我们控制美拉尼西亚、密克罗尼西亚和波利尼西亚群岛、以及印度洋。此一安排的要害在于隐晦地劝阻中国这个庞然大物，兵不血刃地把它引导进太平洋司令部的同盟体系内，此乃北约最终得以遏止苏联之道。<BR><BR>不论我们怎么说和怎么做，中国将在未来的几十年里在军事上投入越来越多的财力，我们唯一现实的目标或许是鼓励中国进行防御性的、而非进攻性的投资。我们的努力需要格外得小心，因为中国在这一点上不同于过去的苏联或今天的俄国，它兼具软力量和硬力量。商界对中国很着迷，不必恳求他们在那里投资，就像恳求他们在非洲和诸多其他地方投资那样。中国传统的权威主义与市场经济的混合在整个亚洲和世界其他地区都有着广泛的文化上的吸引力；同时，因为中国正在改善几亿人民的物质福利，持不同政见者的困境不会完全像苏联的萨哈罗夫和沙兰斯基的困境那样引起人们的注意。民主只有在专制显而易见、令人憎恶且并不成功的地方，如乌克兰和津巴布韦才有吸引力。但是世界上还有灰色地带，如约旦和马来西亚，在这些国家，专制因素保证了秩序和经济增长。<BR><BR>以新加坡为例，民主与权威主义的混合使它不被华盛顿的理想主义者所钟爱，但对于太平洋司令部来说，新加坡尽管面积很小，却是美国在太平洋地区最受欢迎的得力的盟友。它的种族混杂的军事精英集团、对军官和士兵福利同等的关怀、以及在文莱的丛林战学校都是数一数二的。除了远在北边的日本外，新加坡提供了太平洋地区唯一的非美国的基地，以便我们的核动力航空母舰能在此得到维修。它在追捕印尼群岛的伊斯兰恐怖主义分子方面对我们的帮助，丝毫不亚于最可靠的西方盟友在其他地方对我们的帮助。一位在华盛顿的军事未来学家对我说，“哦，新加坡人，他们在各方面都是好样的！”<BR><BR>太平洋司令部的目标，用一位在太平洋服役的海军陆战队上将的话说，必须是“军事上的多边主义”。这不仅仅是个（在取得同盟伙伴同意的情况下）将来与在文莱的“新加坡人”共同训练、与印度空军联合试飞、在泰国每年进行几次大的演习、或者使用在北澳大利亚即将开放的训练设施这样的问题，也是个与友好的亚洲国家的军队在排一级实现共同操作，以便能够在训练地之间不断对美军进行调动的问题。<BR><BR>这将是对北约的超越，北约的战斗力由于新增加了低于原先标准的前东方集团国家的军队而受到削弱。政治因素也倾向于向太平洋地区倾斜：当前美欧关系的紧张妨碍了军事一体化，而我们的太平洋盟国、特别是日本和澳大利亚，希望与美国进行更多的军事交往，以对付实力上升的中国海军。这对我们是有利的。日本军队规模虽小，却拥有一些特殊的精锐作战能力，如特种部队和常规（柴油动力）潜艇战。澳洲人积极进取的开拓风格使他们比英国人更令我们感到亲近。<BR><BR>不过，军事上的多边主义将受到美军技术优势的制约；与那些没有以同等规模投资于高技术装备的亚洲军队很难开展双边训练，军事上的一个经典的教训是，技术优势并不总能产生人们所期待的有利条件。军事上远远领先于所有其他人会产生一种特别的孤独感，即使是最杰出的外交家也不见得能缓解之，因为如果不是根植于对相对力量进行现实主义的评估，外交本身是没有价值的。<BR><BR>当前，中国的崛起所带来的挑战可能看上去是微不足道的，甚至是不存在的。美国海军战舰“满负荷排水量”总计达286万吨，世界其他国家的军舰满负荷排水量全部加起来也不过304万吨，中国海军军舰满负荷排水量只有263,064吨。全世界34艘航空母舰中，美国就占了24艘，中国一艘也没有（这是中国在海啸发生后无法施救的一个主要原因）。统计上的差距还不止这些。但正如战略与预算评估中心的资深分析家罗伯特·沃克指出的，在二十七年的伯罗奔尼撒战争之初，雅典对没有海军的斯巴达有着极大的优势，但斯巴达最终成为了胜利者。<BR><BR>中国已决心大规模增加军事开支，但中国的海军与空军在未来几十年内仍将无法与我们匹敌，因而中国人不会和我们打常规的空战和海战，就像二战中在太平洋发生的战斗。1944年6月底的菲律宾海之战、1944年10月的莱特湾之战和苏里高海峡之战，是美国历史上最后的大规模海战，今后也很可能仍将是如此。但中国人会像恐怖分子所做的那样，以非对称的方式与我们交战。在伊拉克，叛乱分子用汽车炸弹向我们展示了不对称的“低端”，但是，中国人则准备向我们展示这种艺术的“高端”，这就是威胁所在。<BR><BR>中国人有许多办法运用其不够先进的军事力量来取得与我们在政治和战略上的某种对等。据一位我曾经与之交谈的前潜艇指挥官，也是海军战略家的人士分析，中国人已经认真研究了我们最近在巴尔干和波斯湾战争的每一个细节，他们完全了解我们的军事力量对海军投送的依赖程度，海军投送指的是，航空母舰战斗群抵达目标（如伊拉克）附近向敌人的纵深目标发射导弹的能力。为适应这种军事打击，中国人把光纤系统埋在了地下，把防御能力转移到了西部纵深，同时制定了攻击性的战略，使导弹具有打击美国财富和权力的最高象征——航空母舰的能力。中国的一枚巡航导弹即便不能击沉美国航母，但只要击中了，其政治和心理效应将是灾难性的，就像基地组织对双塔的攻击。中国正在集中力量发展导弹和潜艇，以便在特定的遭遇战中羞辱我们，他们的远程导弹计划应当引起美国政策制定者们高度的关注。<BR><BR>在拥有先进的导弹系统后，中国人就能够在我们驰援之前向台湾发射成百上千枚的导弹。这样的打击能力，加之新型的潜艇部队（如果不考虑质量，其水下力量的规模将很快超过我们），将足以使中国人强制其他国家拒绝美国军舰挂靠其港口。中国现有的70艘潜艇的绝大部分是俄国人设计的过时的柴油动力潜艇，但这些潜艇可以被用来在南中国海、东海以及黄海机动布雷。在这些海域，《华尔街日报》记者大卫·拉格写道，“海水深度不均，背景噪音大，海流湍急，热层错动”，这将使对潜艇的侦察异常困难；加之到2010年之前，中国海军将部署17艘新型隐型柴油动力潜艇和3艘核潜艇，人们可以想象中国就能够对我们或对我们的某个亚洲盟国发起骚扰性的攻击，继而，就可能全面展开模糊性强制行动，例如，对台湾的电力电网发起一连串无法追踪的网络攻击，以逐步消磨人心士气，这不是科幻小说；中国人已经在网络战的训练和技术上进行了大量的投资，我们不能因为中国不是民主政体，就认为中国在操纵民主政体选民的心理上不是专家。<BR><BR>在不远的将来，我们可能预料到的是中国某种力量的展示，就像2001年春他们成功地迫使美国海军的EP-3E侦察机降落那样。这样的战术比现在在伊拉克发生的一切更能代表二十一世纪战争形态的趋势，中国在这个竞技场上也将不乏表现的机会。在一次我们每两年一度举行的环太平洋海军演习时，中国能够让它的一艘潜艇潜行在我们的航母战斗群之下，然后浮出海面。中国人已经能够在海面上放置一个移动目标，然后以潜艇或陆基导弹命中之，以显示他们不但有能力威胁航母、而且有能力威胁驱逐舰、护卫舰和巡洋舰。（想一想2000年在也门海岸外对美国配有制导导弹的“科尔”号驱逐舰进行恐怖袭击的政治效应，由此就可以想到，未来对这类军舰的打击将会更加容易。）他们也可以在某次我们在亚洲海岸外举行的“航行自由”演习中撞击我们的一艘军舰。撞击军舰看起来不是什么大不了的事情，但记住：在全球媒体时代，这种的行动会产生重要的战略性后果，因为世界媒体一般是站在破坏者而不是拥有绝对优势的超级大国一边，中国人因而将拥有内在的政治上的有利条件。<BR><BR>对此我们应当如何做出军事上的反应呢？我们不能拘泥于常规的思维及方法。目前，我们的海军是“远洋”力量，负责对和平时期辽阔洋域的控制（这是个不小的功绩），使世界自由贸易的大部分得以进行。如果没有美国的军舰和水手，全球化的现象是不可能发生的。但实际上，我们越来越需要有三类不同的海军：第一类是用以保持我们把海洋作为平台进行离岸轰炸（以支持在伊拉克和阿富汗这样的军事行动）的能力；第二类是用于沿海特种作战（以打击基地设在如印尼、马来西亚和菲律宾南部等地及附近的恐怖主义集团）；第三类用以提高我们的隐型作战能力（在中国大陆沿海、台湾海峡及其他地区巡逻）。鉴于那些运转不灵的太平洋岛国纷纷与中国加强联系，这三大类海军对迫使中国改弦更张都将直接或间接地发挥一定的作用。<BR><BR>我们的航空母舰已经具备了第一类海军所需之功能；我们必须进一步发展另两类海军。特种海军需要众多小型船只，其中就有通用动力公司和洛克希德·马丁公司正在研制的海岸战斗舰，大约400英尺长的海岸战斗舰只需要少量人员，能在很浅的水域行动，并且航速非常快（达到40节），便于调动特种部队（即海军的海豹突击队）。沿海海军的另一个关键性装备是马克-5特种战艇，它只有80英尺长，航速可达50节，航行范围600英里；吃水只有5英尺深的马克-5可以把一个排的特种部队直接送上海滩。马克-5每艘造价约500万美元，五角大楼购买几十艘也仅相当于一架F/A-22战斗机的价格。<BR><BR>发展第三类海军需要真正的变革。尤其是随着媒体越来越无孔不入，我们必须更加隐蔽地行动，以便比方说，能够从潜艇派出突击队登陆一举抓获或干掉恐怖分子，或者把特种部队留下来在任何政府都未进行控制的地区执行使命。当然，潜水艇也有其劣势：它们不能像航空母舰那样提供轰炸的平台，而且成本高昂。虽然如此，它们代表着未来的趋势，这在很大程度上是因为保护航母免遭攻击会越来越得不偿失。<BR><BR>我们的隐型海军如果编入了新型柴油动力潜艇（即澳大利亚、日本、韩国、德国和瑞典海军已经服役或正在建造的那种潜艇），战斗力将得到极大的加强。中国很快也会拥有这种潜艇。但是，由于我们所担负的国际警察的责任，为此必须保有核动力潜艇，因而我们无法改用柴油动力潜艇。不过，我们将会适应我们已拥有的东西。我们已经在为四艘三叉戟核潜艇重新配备常规武器，使其能够支持海豹突击队的调动，并且最终（或许）支持远程的无人驾驶的间谍飞机。这种重新改装的三叉戟核潜艇可以作为支持部署在海岸附近的小型战斗装备的大型母舰。<BR><BR>当然，所有这一切都不会改变我们对在太平洋地区基地使用权的需求。我们能够使用的基地越多，机动性就越强——如支持无人驾驶飞行、实施空中加油，也许最重要的是迫使中国军队把注意力集中在一大堆问题，而不是很少的几个问题上。决不要只给你的对手提供很少的几个需要解决的问题（如发现并打击航母），因为假如是这样的话，他们就能够解决问题。<BR><BR>在关岛北端的安德森空军基地代表着美国在太平洋地区的战略的未来，此处是投送美国军事力量最强大的平台。最近，当我乘坐军用飞机在这里降落的时候，看到了排成长线的B-52轰炸机、C-17巨无霸运输机、F/A-18大黄蜂战斗机和E-2鹰眼侦察机等等。安德森长达3,000英尺的跑道可以起降美国空军各种机型的飞机，并能为航天飞机在需要时提供紧急着陆。四面伸开的跑道和滑行道如此之开阔，我在到达时，几乎没有注意到从“小鹰号”航空母舰上飞来的一架舰载机的机翼，这架飞机正在进行实弹轰炸练习，而在其驻扎的日本港口则无法进行这样的练习。我看到在一处跑道上一辆载满了导弹的卡车。太平洋地区任何其他一处的空军基地都没有储备像安德森基地这么多的武器弹药，安德森基地在任何时候都备有约10万枚的炸弹和导弹，另外，它还储备有6,600万加仑的航空燃料，因而成为美国空军最大的战略补给站。<BR><BR>关岛还驻扎着一个潜艇中队，加上一个正在扩建的海军基地，它的地理位置十分重要，相当于一个海军陆战队或陆军师力量的空军，可以由此覆盖太平洋司令部所负责的几乎全部区域。从美国西海岸飞往北朝鲜要花13个小时，而从关岛出发只需要4个小时。<BR><BR>“这与冲绳不同”，美国驻关岛的空军司令丹尼斯·拉尔森少将在我访问时对我说，“这是美国在太平洋中部的土地，关岛是美国领土”。美国可以在此做任何它想做的事情，进行大规模投资，而毋须担心被人扔出去。的确，安德森吸引我的地方，就是它有极大的空间以供现有的环形防线向南和向西扩展，政府正在拨款数亿美元用于建设。这个距离中国很近的小岛有可能成为美军在世界各地的基地新的布局的中心，从而把美国力量的重心从欧洲转移到亚洲。万一中国与台湾之间爆发冲突，假如我们在关岛拥有一支航空母舰战斗群，我们就能够迫使中国或者去攻击在关岛港口的航母战斗群（这就等于攻击了美国领土，立即就会使中国在全世界的眼里成为侵略者），或者听任其驶出，无论发生哪种情况，航母战斗群只需两天时间就能到达台湾外海。<BR><BR>在冷战期间，美国海军拥有特定的基础设施以应付特定的威胁：与苏联的战争。但现在威胁是多重的和不确定的：我们必须随时准备打仗，比如对北朝鲜的常规战争，或者对中国支持的某个无赖岛国非常规的反叛乱战斗。这就需要在关岛驻守的海军更加机动灵活，为此需要向关岛的居民外购服务，以便集中精力于军事事务。我遇到的一位海军中尉是在太平洋周边这一带长大的，他告诉我，海军计划拓展海滩地，建造更多的单身营房，并把电力系统铺设在地下使其不受爆炸或热辐射之害。“我们现在是有许多空地，不过这是没有意义的”，他说，“问题是，一场全面战争必然会导致各种要求急剧增加，我们怎么应付这种要求？”<BR><BR>上述这些情况可能会有一个问题，把关岛变成西太平洋的夏威夷会让中国人感到轻松，因为我们只给他们提供了一个需要解决的问题：如何威胁或恫吓关岛。反击中国的办法不是集中起来，而是分散出去。那么，我们如何防止把关岛（基地）搞得规模太大呢？<BR><BR>有一系列的办法！我们可以在帕劳修建设施，帕劳是个群岛国家，有20,000居民，位于菲律宾棉兰老岛和密克罗尼西亚联邦之间，我们对它的财政援助是基于我们与之订立的防务协定。我们要继续保持在中亚的基地（靠近中国西部）——其中包括乌兹别克斯坦的喀尔什·哈拉巴德以及吉尔吉斯斯坦的玛纳斯，这两处基地由于对阿富汗战争的需要而被开发和扩建。我们还将在所谓的“合作性安全点”建立基地。<BR><BR>合作性安全点可以是东道国民用机场的某个不起眼的角落，或者是某个地方的一处附近有燃料和机械维护的泥路的跑道，或者是某个友好国家的军用机场（东道国没有与我们签订正式的基地使用协定，但通过私人承包商作为中介与我们有某种非正式的安排）。因为合作性安全点的概念是建立在双方微妙关系的基础上的，这是五角大楼的战争能力与国务院的外交相吻合或应当吻合之处。大型基地存在的问题（如在土耳其的基地——我们在对伊拉克战争前夕已经领教）是：它们是作为美国力量无处不在和威力可怕的象征，而留给东道国的唯一的权力就是拒绝我们使用基地。因此，未来我们更愿意使用不太引人注意的基地，这样对东道国比对我们显然要有利得多，允许我们使用这样的基地会提高东道国的权力，而不是让它感到难堪。<BR><BR>我访问过一些位于东非和亚洲的合作性安全点。它们是这样运作的：美国提供援助来改进维修设施，由此也帮助东道国提高了在本地区内投送海空力量的能力；与此同时，我们与东道国军队以基地为核心定期举行军事演习；我们还对周边地区提供人道主义帮助。这样的民用工程为我国军队在当地媒体上做了积极的宣传，而这些工程在我们对海啸做出反应之前早已存在。海啸事件表明，许多世界媒体首次注意到在世界各地的美军自始至终所做的人道主义工作，其结果是为我们在需要的时候获得东道国同意使用基地营造了积极的外交氛围。<BR><BR>管理合作性安全点的关键性角色经常是由私人承包商来担当的。比如在亚洲，私人承包商通常是退役的美国海军或空军的军士，他很可能是位维修专家，生活在像泰国或菲律宾这样的国家，能说一口流利的当地国语言，也许已经在回国离婚后与当地人结婚，一般来说深受当地人的爱戴。他从东道国军方那里租用基地设施，然后向过往基地的美国空军飞行员收取费用。表面上，他是在给自己做生意，东道国则很喜欢这种方式，因为可以对外宣称它并没有与美军合作。当然，没有人（包括当地媒体）相信这种话，但与美军这种间接而非直接的关系使局势得到了缓和。私人承包商还通过帮助来访的飞行员少惹麻烦（把他们带到适合的旅馆和酒吧，告诉他们应当如何举止），来避免引起不幸的事件。（要是没有在泰国的尤塔堡军港呆了好几年的私人承包商丹·吉纳雷特，该基地可能永远不会得到加强，也就难以被用来提供海啸救援。）<BR><BR>在和这些承包商一起并由他们引导着参观了外国的军用机场后，我发现空军将来可能不大需要多少地面设施以供飞机起降之用，尤其是9·11之后，空军慢慢开始形成过简朴的生活以适应远征作战的思路。这是对过去生活方式的改变，空军在历史上一直比其他兵种的生活要舒适。在地面上维修飞机通常比维修大型船只要省时省力，空军也正在开始领会轻型、致命、以及隐型和非正式关系的概念。为了在太平洋以及其他地区取得成功，海军应当在更大的程度上具有类似的眼界——少考虑一些树大招风的港口访问，而更多地考虑在深夜悄悄地进出港口。<BR><BR>二十一世纪前半叶不会完全像二十世纪后半叶那样稳定，因为世界不会完全像冷战时期那样处于两极格局。北京与华盛顿在太平洋的战斗不会支配世界政治的全部，但它将是一系列地区性争夺中最重要的。不过，它将成为美国对外防御态势构建的焦点。如果我们明智的话，我们应当重新与欧洲协调一致，无论我们在军事上适应中国崛起做得多么得成功，我们目前在太平洋的支配地位显然是不能持久的。亚洲问题专家马克·赫尔普林认为，正当我们在中东努力推进民主化，越来越亲近与我们国内制度相似的国家的时候，中国却准备像美国在冷战时做的那样，为了谋求自身的利益，不道德地乘机攫取巨大的好处。中国人当然希望，比方说，我们对残暴的乌兹别克独裁者伊斯拉姆·卡里莫夫的冷淡态度会更加冷淡，这样就会方便中国从他那里得到更多的石油管道及其他的交易，并可能劝说他拒绝让我们使用喀尔什·哈拉巴德的基地。一旦卡里莫夫被一场吉尔吉斯斯坦那样的起义所推翻，我们将不得不马上采取措施来稳定新政权；否则，就将冒该国的部分地区变成中国人势力范围的风险。<BR><BR>我们还需要认识到，在未来的几年或几十年，欧洲与中国的道德差距会大大缩小，尤其是如果中国的权威主义越来越有所节制，而不断扩大的欧盟变成了一个由布鲁塞尔的官员们以专横的方式管理的不太民主的超国家（superstate）；俄罗斯现在也在明确地走向非民主的方向：俄罗斯总统弗拉基米尔·普京对我们支持乌克兰民主的反应，是同意与中国人在今年下半年举行“大规模”海空军联合演习，此一规模空前的俄中联合军事演习将在中国领土上进行。<BR><BR>因此，认为不再需要介入“玩世不恭”的权力政治游戏的想法是不切实际的，这与完全基于威尔逊的理想、认为可以推行国家外交政策的想法如出一辙。我们必须不断地利用世界的其他部分来对付中国，就像尼克松利用道德上不太完美的国家来对付苏联那样。这很可能导致组建一个全新的北约联盟，它将成为巡航于七大洋的全球舰队。事实上，荷兰、挪威、德国和西班牙正在对能抗导弹攻击的快速战舰、以及用于海滩攻击的登陆平台进行大规模投资，英国和法国正在投资建造新型航空母舰。由于欧洲越来越倾向于避免冲突，并把地缘政治降低到一连串的谈判以及规则的争端方面，强调海权对它来说是恰当的。从本质上讲，海权不如陆权更具威胁性。海权不需要大举登陆就可以进行大规模战斗，例如在海啸救援行动期间，海军陆战队员及水兵每天晚上返回到航母和驱逐舰上。陆军攻城掠地，海军则访问港口。与陆权相比，海权始终是更为有用的现实政治的手段。海权可以令大批军舰游弋在远离本土的遥远海域，但并没有公然的敌意。因为军舰需要很长时间才能到达某一地域，而且威胁性要小于地面部队，海军就给予了外交官们在危机过程中做出回应及回旋的余地来逐步施加压力。以1962年的古巴导弹危机为例，英国专家H·P·威尔莫特写道，“美国人动用海军力量证明是危险度最低的一个选择，在海上，事件发展的缓慢给了双方（足够的）时间，对高度危险的形势加以考虑并做出理性的反应。”<BR><BR>潜艇是这一法则的例外，但潜艇无论是实际上还是象征性地在水下作战（从传媒的雷达屏幕上完全消失）的能力，使政府能够在军事上大胆行动，特别是在谍报领域，而不会触动本国公民敏感的神经。瑞典的中立是建立在它的许多理想主义的公民们可能完全不知道的海军力量的基础上的来之不易的奢侈品；和平主义的日本作为最大的贸易国，越来越依赖其新生的潜艇力量。海权保护着受到条约规制的贸易；并非偶然的是，国际法之父雨果·格老秀斯生活在17世纪的荷兰，那时正是荷兰的海上力量在世界范围内达到巅峰的时候。全球化将使21世纪出现前所未有的海上交通的盛况，这就要求外交家们和海军军官们共同对此进行前所未有的建规立制。随着欧盟在全球范围经济影响的扩大，欧洲会像19世纪的美国和今天的中国那样发现，它必须走向海洋，保护自己的利益。<BR><BR>欧洲人现在正在建造的舰船和其他海军装备将会被纳入到美国的作战网络之中。我们今天视为之“大西洋力量”的欧洲国家可能会发展全球性的海军力量；例如，瑞典的潜艇部队正在帮助训练太平洋的美军如何去搜寻柴油动力潜艇。因此，海洋将可能是北约和欧洲在军事上重振雄风的最好的机会。然而，大西洋联盟无论是在实际上还是在象征意义上都很孱弱，要重新恢复政治上的重要性，北约必须成为一个随时准备义无返顾地投入战斗和杀戮的军事联盟，这就是北约在冷战时的声誉——苏联人对此深信不疑，因而从未对其进行试探。北约东扩当然有助于稳定前华沙条约国家，但是接纳低于标准的军事力量加盟北约，虽然政治上是必要的，却是问题多多。北约越是东扩，就越是流于表面，而难以成为一支战斗力量，北约为保护任何一个成员国而战斗的说辞也就越发令人怀疑。过快地接纳更加低于标准的像乌克兰和格鲁吉亚这样的军队完全不符合北约的利益。我们不能因为某个地方发生了支持民主的示威就宣布要扩大防务联盟，相反，我们必须像现在正在格鲁吉亚所做的那样，在那里，我们派进了海军陆战队达一年时间，来训练格鲁吉亚的武装部队。只有通过这样的方式，在格鲁吉亚正式加入北约的时候，它的成员国身份才具有军事及政治意义。只有把它变成一种机动灵活的力量，以便，比方说，在接到通知的数日或数小时之后就准备好踏上西非的海滩，我们才能够拯救北约。<BR><BR>我们也需要拯救北约！北约——与日益强大的欧盟不同，是由我们来领导的，欧盟自己的防务力量，如果成为一种现实，将不可避免地崛起成为一个竞争性的地区强国，它可能会与中国结盟来抗衡美国。让我把某些政策制定者和专家通常不想说明白的话说得更明白一些，北约与自治性的欧洲防务力量不能同时成功，只能成功一个——我们要的当然是前者，以便在我们与中国对抗的时候，欧洲是我们的一项军事资产，而不是负债。<BR><BR>中国军事上的挑战对于美国海军官兵来说已经成为现实。我最近花了四周的时间深入到一艘名为“本弗尔德”（Benfold）的制导导弹驱逐舰上，该舰在从印尼到新加坡、菲律宾、关岛以至夏威夷的太平洋海面上缓慢游弋。<BR><BR>在我访问期间，“本弗尔德”号完成了海啸救援的使命（包括把食品运送上岸以及重新绘制海岸线），然后根据本舰作战信息中心（一个黑暗的、发出回声的、杂乱的计算机控制台）发出的指令，重新开始作战训练。在这里，一位战术行动军官负责对通常是来自中国或北朝鲜的假想敌或假象的攻击做出反应。<BR><BR>我通过对作战信息中心行动的观察得知，虽然海军作战是通过耳机和计算机键盘来进行，其紧张程度与英勇的城市战相比是毫不逊色的，一个错误的决定会导致灾难性的导弹攻击，对此，体格的健壮和勇敢精神都是与事无补的。<BR><BR>海战是智力性的。威胁来自地平线之上，什么也看不见，一切都被缩减为数学运算。目的更多的是欺骗，而不是侵略——让对方先开火，以便取得政治上的有利条件，但不一定要承受攻击所带来的破坏。<BR><BR>“本弗尔德”号上的士兵在救助海啸受难者的时候积极踊跃，一旦他们离开了印尼水域，他们就对海面以及水下的作战技能训练怨声载道，我甚至产生了这样一种感觉，特别是从海军上士那里感觉到（这些海军军官们对我直言不讳），他们有可能被放在西太平洋，接受与在伊拉克的海军陆战队已经受到的同等程度的试验。迄今，波斯湾地区的主要威胁是像炸“科尔”号那样的不对称攻击，而太平洋地区则是充满了各种各样的威胁，从东南亚穆斯林群岛上越来越猖獗的恐怖主义组织，到在北边的海域与中国潜艇玩“猫和老鼠”的游戏。为对付太平洋地区所有这些可能的威胁，海军必须变得更加灵巧，以便能更好地处理突然来临的非常规性的紧急事态、如海啸。<BR><BR>未来的几十年即将来临。正如一位上士对我说的，“海军应当少花时间在那个小盐泥潭里，应当把更多的时间用在池塘里。”前者指的是波斯湾，后者指的是太平洋。<BR></FONT>]]></description>
</item><item>
<title><![CDATA[各种关于文件的操作vc++]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16300</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/5 17:40:54</pubDate>
<description><![CDATA[各种关于文件的操作在程序设计中十分常见，如果能对这些操作都了如指掌，就可以根据实际情况找到最佳的解决方案，从而可以在较短的时间内编写出高效的代码。本文对Visual C++中有关文件操作进行了全面的介绍，并对在文件操作中经常遇到的一些疑难问题进行了详细分析。 <BR><BR>　　 1． 文件的查找 <BR><BR>　　当对一个文件操作时，如果不知道该文件是否存在，就要首先进行查找。MFC中有一个专门用来进行文件查找的类“CFileFind”，使用它可以方便快捷地进行文件的查找。下面这段代码演示了这个类的最基本使用方法。<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>CString strFileTitle; <BR>CFileFind finder; <BR>BOOL bWorking = finder.FindFile(“C:\\windows\\sysbkup\\*.cab”); <BR>while(bWorking) <BR>{ <BR>　bWorking=finder.FindNextFile(); <BR>　strFileTitle=finder.GetFileTitle(); <BR>} </TD></TR></TBODY></TABLE><BR>　　2． 文件的打开/保存对话框 <BR><BR>　　让用户选择文件进行打开和存储操作时，就要用到文件打开/保存对话框。MFC的类“CFileDialog”用于实现这种功能。使用“CFileDialog”声明一个对象时，第一个BOOL型参数用于指定文件的打开或保存，当为TRUE时将构造一个文件打开对话框，为FALSE时构造一个文件保存对话框。 <BR><BR>　　在构造“CFileDialog”对象时，如果在参数中指定了“OFN_ALLOWMULTISELECT”风格，则在此对话框中可以进行多选操作。此时要重点注意为此“CFileDialog”对象的“m_ofn.lpstrFile”分配一块内存，用于存储多选操作所返回的所有文件路径名，如果不进行分配或分配的内存过小就会导致操作失败。下面这段程序演示了文件打开对话框的使用方法。 <BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>CFileDialog mFileDlg(TRUE, NULL,NULL, OFN_HIDEREADONLY|OFN_OVER <BR>WRITEPROMPT|OFN_ALLOWMULTISELECT,“All Files (*.*)|*.*| |”, AfxGetMainWnd()); <BR>CString str(“ ”, 10000); <BR>mFileDlg.m_ofn.lpstrFile=str.GetBuffer(10000); <BR>str.ReleaseBuffer(); <BR>POSITION mPos=mFileDlg.GetStartPosition(); <BR>CString pathName(“ ”, 128); <BR>CFileStatus status; <BR>while(mPos!=NULL) <BR>{ <BR>　pathName=mFileDlg.GetNextPathName(mPos); <BR>　CFile::GetStatus(pathName, status); <BR>} </TD></TR></TBODY></TABLE><BR>　　 3． 文件的读写 <BR><BR>　　文件的读写非常重要，下面将重点进行介绍。文件读写最普通的方法是直接使用“CFile”类进行，如文件的读写可以使用下面的方法： <BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>//对文件进行读操作 <BR>char sRead[2]; <BR>CFile mFile(_T(“user.txt”),CFile::modeRead); <BR>if(mFile.GetLength()&lt;2) <BR>　return; <BR>mFile.Read(sRead，2); <BR>mFile.Close(); <BR>//对文件进行写操作 <BR>CFile mFile(_T(“user.txt”), CFile::modeWrite|CFile::modeCreate); <BR>mFile.Write(sRead，2); <BR>mFile.Flush(); <BR>mFile.Close(); </TD></TR></TBODY></TABLE><BR>　　虽然这种方法最为基本，但是它使用烦琐，而且功能非常简单。这里推荐的是使用“CArchive”，它的使用方法简单且功能十分强大。首先还是用“CFile”声明一个对象，然后用这个对象的指针做参数声明一个“CArchive”对象，这样就可以非常方便地存储各种复杂的数据类型了。它的使用方法见下例： <BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>//对文件进行写操作 <BR>CString strTemp; <BR>CFile mFile; <BR>mFile.Open(“d:\\dd\\try.TRY”,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite); <BR>CArchive ar(&amp;mFile，CArchive::store); <BR>ar&lt;&lt;strTemp; <BR>ar.Close(); <BR>mFile.Close(); <BR>//对文件进行读操作 <BR>CFile mFile; <BR>if(mFile.Open(“d:\\dd\\try.TRY”，CFile::modeRead)==0) <BR>　return; <BR>CArchive ar(&amp;mFile，CArchive::load); <BR>ar&gt;&gt;strTemp; <BR>ar.Close(); <BR>mFile.Close(); </TD></TR></TBODY></TABLE><BR>　　 “CArchive”的“&lt;&lt;”和“&gt;&gt;”操作符用于简单数据类型的读写，对于“CObject”派生类的对象的存取要使用ReadObject()和WriteObject()。使用“CArchive”的ReadClass()和WriteClass()还可以进行类的读写，如： <BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>//存储CAboutDlg类 <BR>ar.WriteClass(RUNTIME_CLASS(CAboutDlg)); <BR>//读取CAboutDlg类 <BR>CRuntimeClass*mRunClass=ar.Read <BR>Class(); <BR>//使用CAboutDlg类 <BR>CObject* pObject=mRunClass-&gt;CreateObject(); <BR>((CDialog* )pObject)-&gt;DoModal(); </TD></TR></TBODY></TABLE><BR>　　虽然VC提供的文档/视结构中的文档也可进行这些操作，但是不容易理解、使用和管理，如果要进行的文件操作只是简单的读写整行的字符串，建议使用“CStdioFile”，用它来进行此类操作非常方便，如下例： <BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>CStdioFile mFile; <BR>CFileException mExcept; <BR>mFile.Open( “d:\\temp\\aa.bat”, CFile::modeWrite, &amp;mExcept); <BR>CString string=“I am a string.”; <BR>mFile.WriteString(string); <BR>mFile.Close(); </TD></TR></TBODY></TABLE><BR>　　4．临时文件的使用 <BR><BR>　　正规软件经常用到临时文件，经常可以看到“C:\Windows\Temp”目录下有大量的扩展名为“.tmp”的文件，这些就是程序运行时建立的临时文件。临时文件的使用方法基本与常规文件一样，只是文件名应该调用函数GetTempFileName()获得。它的第一个参数是建立此临时文件的路径，第二个参数是建立临时文件名的前缀，第四个参数用于得到建立的临时文件名。得到此临时文件名以后，就可以用它来建立并操作文件了，如： <BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#b3b3b3 border=1>
<TBODY>
<TR>
<TD>char szTempPath[_MAX_PATH]，szTempfile[_MAX_PATH]; <BR>GetTempPath(_MAX_PATH, szTempPath); <BR>GetTempFileName(szTempPath，_T (“my_”)，0，szTempfile); <BR>CFile m_tempFile(szTempfile，CFile:: modeCreate|CFile:: modeWrite); <BR>char m_char=‘a’; <BR>m_tempFile.Write(&amp;m_char，2); <BR>m_tempFile.Close(); </TD></TR></TBODY></TABLE><BR>　　5．文件的复制、删除等 <BR><BR>　　MFC中没有提供直接进行这些操作的功能，因而要使用SDK。SDK中的文件相关函数常用的有CopyFile()、CreateDirectory()、DeleteFile()、MoveFile()。它们的用法很简单，可参考MSDN。 <BR><BR><!--新闻内容结束-->]]></description>
</item><item>
<title><![CDATA[STL实践指南]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16299</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/5 17:33:40</pubDate>
<description><![CDATA[<A><FONT size=1>　</FONT></A>
<P><A><FONT size=1>　</FONT></A></P>
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>
<TBODY>
<TR>
<TD>
<P><A class=diary_title href="http://www.blogcn.com/user62/chenglm/blog/25003677.html"><FONT class=diary_title size=1>STL实践指南</FONT></A><A name=25003677></A><FONT size=1> <BR><BR>作者：Jeff&nbsp;Bogan&nbsp;<BR>翻译：周翔&nbsp;<BR>出处：</FONT><A href="http://www.blogcn.com/images/aurl.gif" target=_blank><FONT size=1><IMG onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 alt=::URL:: hspace=2 src="http://www.blogcn.com/images/aurl.gif" onload="java_script_:if(this.width>500)this.width=500" align=absBottom border=0></FONT></A><A href="http://www.codeproject.com/vcpp/stl/PracticalGuideStl.asp" target=_blank><FONT size=1>http://www.codeproject.com/vcpp/stl/PracticalGuideStl.asp</FONT></A><FONT size=1> &nbsp;<BR><BR>译者注<BR><BR>这是一篇指导您如何在Microsoft&nbsp;Visual&nbsp;Studio下学习STL并进行实践的文章。这篇文章从STL的基础知识讲起，循序渐进，逐步深入，涉及到了STL编写代码的方法、STL代码的编译和调试、命名空间（namespace）、STL中的ANSI&nbsp;/&nbsp;ISO字符串、各种不同类型的容器（container）、模板（template）、游标（Iterator）、算法（Algorithms）、分配器（Allocator）、容器的嵌套等方面的问题，作者在这篇文章中对读者提出了一些建议，并指出了使用STL时应该注意的问题。这篇文章覆盖面广，视角全面。不仅仅适合初学者学习STL，更是广大读者使用STL编程的实践指南。&nbsp;<BR><BR>STL简介&nbsp;<BR><BR>STL&nbsp;(标准模版库，Standard&nbsp;Template&nbsp;Library)是当今每个从事C++编程的人需要掌握的一项不错的技术。我觉得每一个初学STL的人应该花费一段时间来熟悉它，比如，学习STL时会有急剧升降的学习曲线，并且有一些命名是不太容易凭直觉就能够记住的（也许是好记的名字已经被用光了），然而如果一旦你掌握了STL，你就不会觉得头痛了。和MFC相比，STL更加复杂和强大。&nbsp;<BR><BR>STL有以下的一些优点：&nbsp;<BR><BR><BR>可以方便容易地实现搜索数据或对数据排序等一系列的算法；<BR>调试程序时更加安全和方便；<BR>即使是人们用STL在UNIX平台下写的代码你也可以很容易地理解（因为STL是跨平台的）。<BR><BR><BR>背景知识<BR><BR>写这一部分是让一些初学计算机的读者在富有挑战性的计算机科学领域有一个良好的开端，而不必费力地了解那无穷无尽的行话术语和沉闷的规则，在这里仅仅把那些行话和规则当作STLer们用于自娱的创造品吧。&nbsp;<BR><BR>使用代码&nbsp;<BR><BR>本文使用的代码在STL实践中主要具有指导意义。&nbsp;<BR><BR>一些基础概念的定义&nbsp;<BR><BR>模板（Template）——类（以及结构等各种数据类型和函数）的宏（macro）。有时叫做甜饼切割机（cookie&nbsp;cutter），正规的名称应叫做范型（generic）——一个类的模板叫做范型类（generic&nbsp;class），而一个函数的模板也自然而然地被叫做范型函数（generic&nbsp;function）。&nbsp;<BR><BR>STL——标准模板库，一些聪明人写的一些模板，现在已成为每个人所使用的标准C++语言中的一部分。&nbsp;<BR><BR>容器（Container）——可容纳一些数据的模板类。STL中有vector，set，map，multimap和deque等容器。&nbsp;<BR><BR>向量（Vector）——基本数组模板，这是一个容器。&nbsp;<BR><BR>游标（Iterator）——这是一个奇特的东西，它是一个指针，用来指向STL容器中的元素，也可以指向其它的元素。&nbsp;<BR><BR>Hello&nbsp;World程序&nbsp;<BR><BR>我愿意在我的黄金时间在这里写下我的程序：一个hello&nbsp;world程序。这个程序将一个字符串传送到一个字符向量中，然后每次显示向量中的一个字符。向量就像是盛放变长数组的花园，大约所有STL容器中有一半是基于向量的，如果你掌握了这个程序，你便差不多掌握了整个STL的一半了。&nbsp;<BR><BR>//程序：向量演示一&nbsp;<BR>//目的：理解STL中的向量&nbsp;<BR><BR>//&nbsp;#include&nbsp;"stdafx.h"&nbsp;-如果你使用预编译的头文件就包含这个头文件&nbsp;<BR>#include&nbsp;&lt;vector&gt;&nbsp;//&nbsp;STL向量的头文件。这里没有".h"。&nbsp;<BR>#include&nbsp;&lt;iostream&gt;&nbsp;//&nbsp;包含cout对象的头文件。&nbsp;<BR>using&nbsp;namespace&nbsp;std;&nbsp;//保证在程序中可以使用std命名空间中的成员。&nbsp;<BR>char*&nbsp;szHW&nbsp;=&nbsp;"Hello&nbsp;World";&nbsp;//这是一个字符数组，以”\0”结束。&nbsp;<BR><BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;char&gt;&nbsp;vec;&nbsp;//声明一个字符向量vector&nbsp;(STL中的数组)&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//为字符数组定义一个游标iterator。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;char&gt;::iterator&nbsp;vi;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//初始化字符向量，对整个字符串进行循环，&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//用来把数据填放到字符向量中，直到遇到”\0”时结束。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;char*&nbsp;cptr&nbsp;=&nbsp;szHW;&nbsp;//&nbsp;将一个指针指向“Hello&nbsp;World”字符串&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(*cptr&nbsp;!=&nbsp;'\0')&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;vec.push_back(*cptr);&nbsp;cptr++;&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;push_back函数将数据放在向量的尾部。&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;将向量中的字符一个个地显示在控制台&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(vi=vec.begin();&nbsp;vi!=vec.end();&nbsp;vi++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;这是STL循环的规范化的开始——通常是&nbsp;"!="&nbsp;，&nbsp;而不是&nbsp;"&lt;"&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;因为"&lt;"&nbsp;在一些容器中没有定义。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;begin()返回向量起始元素的游标（iterator），end()返回向量末尾元素的游标（iterator）。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cout&nbsp;&lt;&lt;&nbsp;*vi;&nbsp;}&nbsp;//&nbsp;使用运算符&nbsp;“*”&nbsp;将数据从游标指针中提取出来。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;endl;&nbsp;//&nbsp;换行&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>push_back是将数据放入vector（向量）或deque（双端队列）的标准函数。Insert是一个与之类似的函数，然而它在所有容器中都可以使用，但是用法更加复杂。end()实际上是取末尾加一（取容器中末尾的前一个元素），以便让循环正确运行——它返回的指针指向最靠近数组界限的数据。就像普通循环中的数组，比如for&nbsp;(i=0;&nbsp;i&lt;6;&nbsp;i++)&nbsp;{ar[i]&nbsp;=&nbsp;i;}&nbsp;——ar[6]是不存在的，在循环中不会达到这个元素，所以在循环中不会出现问题。&nbsp;<BR><BR>STL的烦恼之一——初始化&nbsp;<BR><BR>STL令人烦恼的地方是在它初始化的时候。STL中容器的初始化比C/C++数组初始化要麻烦的多。你只能一个元素一个元素地来，或者先初始化一个普通数组再通过转化填放到容器中。我认为人们通常可以这样做：&nbsp;<BR><BR>//程序：初始化演示&nbsp;<BR>//目的：为了说明STL中的向量是怎样初始化的。&nbsp;<BR><BR>#include&nbsp;&lt;cstring&gt;&nbsp;//&nbsp;&lt;cstring&gt;和&lt;string.h&gt;相同&nbsp;<BR>#include&nbsp;&lt;vector&gt;&nbsp;<BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>int&nbsp;ar[10]&nbsp;=&nbsp;{&nbsp;12,&nbsp;45,&nbsp;234,&nbsp;64,&nbsp;12,&nbsp;35,&nbsp;63,&nbsp;23,&nbsp;12,&nbsp;55&nbsp;};&nbsp;<BR>char*&nbsp;str&nbsp;=&nbsp;"Hello&nbsp;World";&nbsp;<BR><BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;int&gt;&nbsp;vec1(ar,&nbsp;ar+10);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;char&gt;&nbsp;vec2(str,&nbsp;str+strlen(str));&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>在编程中，有很多种方法来完成同样的工作。另一种填充向量的方法是用更加熟悉的方括号，比如下面的程序：&nbsp;<BR><BR>//程序：向量演示二&nbsp;<BR>//目的：理解带有数组下标和方括号的STL向量&nbsp;<BR><BR>#include&nbsp;&lt;cstring&gt;&nbsp;<BR>#include&nbsp;&lt;vector&gt;&nbsp;<BR>#include&nbsp;&lt;iostream&gt;&nbsp;<BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>char*&nbsp;szHW&nbsp;=&nbsp;"Hello&nbsp;World";&nbsp;<BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;char&gt;&nbsp;vec(strlen(sHW));&nbsp;//为向量分配内存空间&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i,&nbsp;k&nbsp;=&nbsp;0;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;char*&nbsp;cptr&nbsp;=&nbsp;szHW;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(*cptr&nbsp;!=&nbsp;'\0')&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;vec[k]&nbsp;=&nbsp;*cptr;&nbsp;cptr++;&nbsp;k++;&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(i=0;&nbsp;i&lt;vec.size();&nbsp;i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cout&nbsp;&lt;&lt;&nbsp;vec[i];&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>这个例子更加清晰，但是对游标（iterator）的操作少了，并且定义了额外的整形数作为下标，而且，你必须清楚地在程序中说明为向量分配多少内存空间。&nbsp;<BR><BR>命名空间（Namespace）&nbsp;<BR><BR>与STL相关的概念是命名空间（namespace）。STL定义在std命名空间中。有3种方法声明使用的命名空间：&nbsp;<BR><BR>1．用using关键字使用这个命名空间，在文件的顶部，但在声明的头文件下面加入：&nbsp;<BR><BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>这对单个工程来说是最简单也是最好的方法，这个方法可以把你的代码限定在std命名空间中。&nbsp;<BR><BR>2．使用每一个模板前对每一个要使用的对象进行声明（就像原形化）：&nbsp;<BR><BR>using&nbsp;std::cout;&nbsp;<BR>using&nbsp;std::endl;&nbsp;<BR>using&nbsp;std::flush;&nbsp;<BR>using&nbsp;std::set;&nbsp;<BR>using&nbsp;std::inserter;&nbsp;<BR><BR>尽管这样写有些冗长，但可以对记忆使用的函数比较有利，并且你可以容易地声明并使用其他命名空间中的成员。&nbsp;<BR><BR>3．在每一次使用std命名空间中的模版时，使用std域标识符。比如：&nbsp;<BR><BR>typedef&nbsp;std::vector&lt;std::string&gt;&nbsp;VEC_STR;&nbsp;<BR><BR>这种方法虽然写起来比较冗长，但是是在混合使用多个命名空间时的最好方法。一些STL的狂热者一直使用这种方法，并且把不使用这种方法的人视为异类。一些人会通过这种方法建立一些宏来简化问题。&nbsp;<BR><BR>除此之外，你可以把using&nbsp;namespace&nbsp;std加入到任何域中，比如可以加入到函数的头部或一个控制循环体中。&nbsp;<BR><BR>一些建议&nbsp;<BR><BR>为了避免在调试模式（debug&nbsp;mode）出现恼人的警告，使用下面的编译器命令：&nbsp;<BR><BR>#pragma&nbsp;warning(disable:&nbsp;4786)&nbsp;<BR><BR>另一条需要注意的是，你必须确保在两个尖括号之间或尖括号和名字之间用空格隔开，因为是为了避免同“&gt;&gt;”移位运算符混淆。比如&nbsp;<BR><BR>vector&nbsp;&lt;list&lt;int&gt;&gt;&nbsp;veclis;&nbsp;<BR><BR>这样写会报错，而这样写：&nbsp;<BR><BR>vector&nbsp;&lt;list&nbsp;&lt;int&gt;&nbsp;&gt;&nbsp;veclis;&nbsp;<BR><BR>就可以避免错误。&nbsp;<BR><BR>另一种容器——集合（set）&nbsp;<BR><BR>这是微软帮助文档中对集合（set）的解释：“描述了一个控制变长元素序列的对象（注：set中的key和value是Key类型的，而map中的key和value是一个pair结构中的两个分量）的模板类，每一个元素包含了一个排序键（sort&nbsp;key）和一个值(value)。对这个序列可以进行查找、插入、删除序列中的任意一个元素，而完成这些操作的时间同这个序列中元素个数的对数成比例关系，并且当游标指向一个已删除的元素时，删除操作无效。”&nbsp;<BR><BR>而一个经过更正的和更加实际的定义应该是：一个集合（set）是一个容器，它其中所包含的元素的值是唯一的。这在收集一个数据的具体值的时候是有用的。集合中的元素按一定的顺序排列，并被作为集合中的实例。如果你需要一个键/值对（pair）来存储数据，map是一个更好的选择。一个集合通过一个链表来组织，在插入操作和删除操作上比向量（vector）快，但查找或添加末尾的元素时会有些慢。&nbsp;<BR><BR>下面是一个例子：&nbsp;<BR><BR>//程序：集合演示&nbsp;<BR>//目的：理解STL中的集合（set）&nbsp;<BR><BR>#include&nbsp;&lt;string&gt;&nbsp;<BR>#include&nbsp;&lt;set&gt;&nbsp;<BR>#include&nbsp;&lt;iostream&gt;&nbsp;<BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;&lt;string&gt;&nbsp;strset;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;&lt;string&gt;::iterator&nbsp;si;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strset.insert("cantaloupes"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strset.insert("apple"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strset.insert("orange"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strset.insert("banana"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strset.insert("grapes"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strset.insert("grapes"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(si=strset.begin();&nbsp;si!=strset.end();&nbsp;si++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cout&nbsp;&lt;&lt;&nbsp;*si&nbsp;&lt;&lt;&nbsp;"&nbsp;";&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>//&nbsp;输出：&nbsp;apple&nbsp;banana&nbsp;cantaloupes&nbsp;grapes&nbsp;orange&nbsp;<BR>//注意：输出的集合中的元素是按字母大小顺序排列的，而且每个值都不重复。&nbsp;<BR><BR>如果你感兴趣的话，你可以将输出循环用下面的代码替换：&nbsp;<BR><BR>copy(strset.begin(),&nbsp;strset.end(),&nbsp;ostream_iterator&lt;string&gt;(cout,&nbsp;"&nbsp;"</FONT><A href="http://www.blogcn.com/images/wink.gif" target=_blank><A href="http://www.blogcn.com/images/wink.gif" target=_blank><FONT size=1><IMG src="http://www.blogcn.com/images/wink.gif" onload="if(this.width onmousewheel='return bbimg(this)' border='0'  border='0' title='点击在新窗口查看原始图片' onload='java_script_:if(this.width>500)this.width=500'></a>screen.width/2)this.style.width=screen.width/2;" border=0></FONT></A><FONT size=1>);&nbsp;<BR><BR>集合（set）虽然更强大，但我个人认为它有些不清晰的地方而且更容易出错，如果你明白了这一点，你会知道用集合（set）可以做什么。&nbsp;<BR><BR>所有的STL容器&nbsp;<BR><BR>容器（Container）的概念的出现早于模板（template），它原本是一个计算机科学领域中的一个重要概念，但在这里，它的概念和STL混合在一起了。下面是在STL中出现的7种容器：&nbsp;<BR><BR>vector（向量）——STL中标准而安全的数组。只能在vector&nbsp;的“前面”增加数据。&nbsp;<BR><BR>deque（双端队列double-ended&nbsp;queue）——在功能上和vector相似，但是可以在前后两端向其中添加数据。&nbsp;<BR><BR>list（列表）——游标一次只可以移动一步。如果你对链表已经很熟悉，那么STL中的list则是一个双向链表（每个节点有指向前驱和指向后继的两个指针）。&nbsp;<BR><BR>set（集合）——包含了经过排序了的数据，这些数据的值(value)必须是唯一的。&nbsp;<BR><BR>map（映射）——经过排序了的二元组的集合，map中的每个元素都是由两个值组成，其中的key（键值，一个map中的键值必须是唯一的）是在排序或搜索时使用，它的值可以在容器中重新获取；而另一个值是该元素关联的数值。比如，除了可以ar[43]&nbsp;=&nbsp;"overripe"这样找到一个数据，map还可以通过ar["banana"&gt;&nbsp;=&nbsp;"overripe"这样的方法找到一个数据。如果你想获得其中的元素信息，通过输入元素的全名就可以轻松实现。&nbsp;<BR><BR>multiset（多重集）——和集合（set）相似，然而其中的值不要求必须是唯一的（即可以有重复）。&nbsp;<BR><BR>multimap（多重映射）——和映射（map）相似，然而其中的键值不要求必须是唯一的（即可以有重复）。&nbsp;<BR><BR>注意：如果你阅读微软的帮助文档，你会遇到对每种容器的效率的陈述。比如：log(n*n)的插入时间。除非你要处理大量的数据，否则这些时间的影响是可以忽略的。如果你发现你的程序有明显的滞后感或者需要处理时间攸关（time&nbsp;critical）的事情，你可以去了解更多有关各种容器运行效率的话题。&nbsp;<BR><BR>怎样在一个map中使用类？&nbsp;<BR><BR>Map是一个通过key（键）来获得value(值)的模板类。&nbsp;<BR><BR>另一个问题是你希望在map中使用自己的类而不是已有的数据类型，比如现在已经用过的int。建立一个“为模板准备的（template-ready）”类，你必须确保在该类中包含一些成员函数和重载操作符。下面的一些成员是必须的：&nbsp;<BR><BR><BR>缺省的构造函数（通常为空）&nbsp;<BR><BR>拷贝构造函数&nbsp;<BR><BR>重载的”=”运算符&nbsp;<BR><BR>你应该重载尽可能多的运算符来满足特定模板的需要，比如，如果你想定义一个类作为&nbsp;map中的键（key），你必须重载相关的运算符。但在这里不对重载运算符做过多讨论了。&nbsp;<BR><BR>//程序：映射自定义的类。&nbsp;<BR>//目的：说明在map中怎样使用自定义的类。&nbsp;<BR><BR>#include&nbsp;&lt;string&gt;&nbsp;<BR>#include&nbsp;&lt;iostream&gt;&nbsp;<BR>#include&nbsp;&lt;vector&gt;&nbsp;<BR>#include&nbsp;&lt;map&gt;&nbsp;<BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>class&nbsp;CStudent&nbsp;<BR>{&nbsp;<BR>public&nbsp;:&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;nStudentID;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;nAge;&nbsp;<BR>public&nbsp;:&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//缺省构造函数——通常为空&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CStudent()&nbsp;{&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;完整的构造函数&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CStudent(int&nbsp;nSID,&nbsp;int&nbsp;nA)&nbsp;{&nbsp;nStudentID=nSID;&nbsp;nAge=nA;&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//拷贝构造函数&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CStudent(const&nbsp;CStudent&amp;&nbsp;ob)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;nStudentID=ob.nStudentID;&nbsp;nAge=ob.nAge;&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;重载“=”&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;operator&nbsp;=&nbsp;(const&nbsp;CStudent&amp;&nbsp;ob)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;nStudentID=ob.nStudentID;&nbsp;nAge=ob.nAge;&nbsp;}&nbsp;<BR>};&nbsp;<BR><BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;map&nbsp;&lt;string,&nbsp;CStudent&gt;&nbsp;mapStudent;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;mapStudent["Joe&nbsp;Lennon"&gt;&nbsp;=&nbsp;CStudent(103547,&nbsp;22);&nbsp;<BR>&nbsp;&nbsp;&nbsp;mapStudent["Phil&nbsp;McCartney"&gt;&nbsp;=&nbsp;CStudent(100723,&nbsp;22);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;mapStudent["Raoul&nbsp;Starr"&gt;&nbsp;=&nbsp;CStudent(107350,&nbsp;24);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;mapStudent["Gordon&nbsp;Hamilton"&gt;&nbsp;=&nbsp;CStudent(102330,&nbsp;22);&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;通过姓名来访问Cstudent类中的成员&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;"The&nbsp;Student&nbsp;number&nbsp;for&nbsp;Joe&nbsp;Lennon&nbsp;is&nbsp;"&nbsp;&lt;&lt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(mapStudent["Joe&nbsp;Lennon"&gt;.nStudentID)&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>typedef&nbsp;<BR><BR>如果你喜欢使用typedef关键字，下面是个例子：&nbsp;<BR><BR>typedef&nbsp;set&nbsp;&lt;int&gt;&nbsp;SET_INT;&nbsp;<BR>typedef&nbsp;SET_INT::iterator&nbsp;SET_INT_ITER&nbsp;<BR><BR>编写代码的一个习惯就是使用大写字母和下划线来命名数据类型。&nbsp;<BR><BR>ANSI&nbsp;/&nbsp;ISO字符串&nbsp;<BR><BR>ANSI/ISO字符串在STL容器中使用得很普遍。这是标准的字符串类，并得到了广泛地提倡，然而在缺乏格式声明的情况下就会出问题。你必须使用“&lt;&lt;”和输入输出流（iostream）代码（如dec,&nbsp;width等）将字符串串联起来。&nbsp;<BR><BR>可在必要的时候使用c_str()来重新获得字符指针。&nbsp;<BR><BR>游标（Iterator）&nbsp;<BR><BR>我说过游标是指针，但不仅仅是指针。游标和指针很像，功能很像指针，但是实际上，游标是通过重载一元的”*”和”-&gt;”来从容器中间接地返回一个值。将这些值存储在容器中并不是一个好主意，因为每当一个新值添加到容器中或者有一个值从容器中删除，这些值就会失效。在某种程度上，游标可以看作是句柄（handle）。通常情况下游标（iterator）的类型可以有所变化，这样容器也会有几种不同方式的转变：&nbsp;<BR><BR>iterator——对于除了vector以外的其他任何容器，你可以通过这种游标在一次操作中在容器中朝向前的方向走一步。这意味着对于这种游标你只能使用“++”操作符。而不能使用“--”或“+=”操作符。而对于vector这一种容器，你可以使用“+=”、“—”、“++”、“-=”中的任何一种操作符和“&lt;”、“&lt;=”、“&gt;”、“&gt;=”、“==”、“!=”等比较运算符。&nbsp;<BR><BR>reverse_iterator&nbsp;–&nbsp;如果你想用向后的方向而不是向前的方向的游标来遍历除vector之外的容器中的元素，你可以使用reverse_iterator&nbsp;来反转遍历的方向，你还可以用rbegin()来代替begin()，用rend()代替end()，而此时的“++”操作符会朝向后的方向遍历。&nbsp;<BR><BR>const_iterator&nbsp;——一个向前方向的游标，它返回一个常数值。你可以使用这种类型的游标来指向一个只读的值。&nbsp;<BR><BR>const_reverse_iterator&nbsp;——一个朝反方向遍历的游标，它返回一个常数值。&nbsp;<BR><BR>Set和Map中的排序&nbsp;<BR><BR>除了类型和值外，模板含有其他的参数。你可以传递一个回调函数（通常所说的声明“predicate”——这是带有一个参数的函数返回一个布尔值）。例如，如果你想自动建立一个集合，集合中的元素按升序排列，你可以用鲜明的方法建立一个set类：&nbsp;<BR><BR>set&nbsp;&lt;int,&nbsp;greater&lt;int&gt;&nbsp;&gt;&nbsp;set1&nbsp;<BR><BR>greater&nbsp;&lt;int&gt;是另一个模板函数（范型函数），当值放置在容器中后，它用来为这些值排序。如果你想按降序排列这些值，你可以这样写：&nbsp;<BR><BR>set&nbsp;&lt;int,&nbsp;less&lt;int&gt;&nbsp;&gt;&nbsp;set1&nbsp;<BR><BR>在实现算法时，将声明（predicate）作为一个参数传递到一个STL模板类中时会遇到很多的其他情况，下面将会对这些情况进行详细描述。&nbsp;<BR><BR>STL&nbsp;的烦恼之二——错误信息&nbsp;<BR><BR>这些模板的命名需要对编译器进行扩充，所以当编译器因某种原因发生故障时，它会列出一段很长的错误信息，并且这些错误信息晦涩难懂。我觉得处理这样的难题没有什么好办法。但最好的方法是去查找并仔细研究错误信息指明代码段的尾端。还有一个烦恼就是：当你双击错误信息时，它会将错误指向模版库的内部代码，而这些代码就更难读了。一般情况下，纠错的最好方法是重新检查一下你的代码，运行时忽略所有的警告信息。&nbsp;<BR><BR>算法（Algorithms）&nbsp;<BR><BR>算法是模板中使用的函数。这才真正开始体现STL的强大之处。你可以学习一些大多数模板容器中都会用到的一些算法函数，这样你可以通过最简便的方式进行排序、查找、交换等操作。STL中包含着一系列实现算法的函数。比如：sort(vec.begin()+1,&nbsp;vec.end()-1)可以实现对除第一个和最后一个元素的其他元素的排序操作。&nbsp;<BR><BR>容器自身不能使用算法，但两个容器中的游标可以限定容器中使用算法的元素。既然这样，算法不直接受到容器的限制，而是通过采用游标，算法才能够得到支持。此外，很多次你会遇到传递一个已经准备好了的函数（以前提到的声明：predicate）作为参数，你也可以传递以前的旧值。&nbsp;<BR><BR>下面的例子演示了怎样使用算法：&nbsp;<BR><BR>//程序：测试分数&nbsp;<BR>//目的：通过对向量中保存的分数的操作说明怎样使用算法&nbsp;<BR><BR>#include&nbsp;&lt;algorithm&gt;&nbsp;//如果要使用算法函数，你必须要包含这个头文件。&nbsp;<BR>#include&nbsp;&lt;numeric&gt;&nbsp;//&nbsp;包含accumulate（求和）函数的头文件&nbsp;<BR>#include&nbsp;&lt;vector&gt;&nbsp;<BR>#include&nbsp;&lt;iostream&gt;&nbsp;<BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>int&nbsp;testscore[]&nbsp;=&nbsp;{67,&nbsp;56,&nbsp;24,&nbsp;78,&nbsp;99,&nbsp;87,&nbsp;56};&nbsp;<BR><BR>//判断一个成绩是否通过了考试&nbsp;<BR>bool&nbsp;passed_test(int&nbsp;n)&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(n&nbsp;&gt;=&nbsp;60);&nbsp;<BR>}&nbsp;<BR><BR>//&nbsp;判断一个成绩是否不及格&nbsp;<BR>bool&nbsp;failed_test(int&nbsp;n)&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(n&nbsp;&lt;&nbsp;60);&nbsp;<BR>}&nbsp;<BR><BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;total;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;初始化向量，使之能够装入testscore数组中的元素&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;int&gt;&nbsp;vecTestScore(testscore,&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;testscore&nbsp;+&nbsp;sizeof(testscore)&nbsp;/&nbsp;sizeof(int));&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;int&gt;::iterator&nbsp;vi;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;排序并显示向量中的数据&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;sort(vecTestScore.begin(),&nbsp;vecTestScore.end());&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;"Sorted&nbsp;Test&nbsp;Scores:"&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(vi=vecTestScore.begin();&nbsp;vi&nbsp;!=&nbsp;vecTestScore.end();&nbsp;vi++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cout&nbsp;&lt;&lt;&nbsp;*vi&nbsp;&lt;&lt;&nbsp;",&nbsp;";&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;显示统计信息&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;min_element&nbsp;返回一个&nbsp;_iterator_&nbsp;类型的对象，该对象指向值最小的那个元素。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//“*”运算符提取元素中的值。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vi&nbsp;=&nbsp;min_element(vecTestScore.begin(),&nbsp;vecTestScore.end());&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;"The&nbsp;lowest&nbsp;score&nbsp;was&nbsp;"&nbsp;&lt;&lt;&nbsp;*vi&nbsp;&lt;&lt;&nbsp;"."&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//与min_element类似，max_element是选出最大值。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vi&nbsp;=&nbsp;max_element(vecTestScore.begin(),&nbsp;vecTestScore.end());&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;"The&nbsp;highest&nbsp;score&nbsp;was&nbsp;"&nbsp;&lt;&lt;&nbsp;*vi&nbsp;&lt;&lt;&nbsp;"."&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;使用声明函数（predicate&nbsp;function，指vecTestScore.begin()和vecTestScore.end()）来确定通过考试的人数。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;count_if(vecTestScore.begin(),&nbsp;vecTestScore.end(),&nbsp;passed_test)&nbsp;&lt;&lt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;out&nbsp;of&nbsp;"&nbsp;&lt;&lt;&nbsp;vecTestScore.size()&nbsp;&lt;&lt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;students&nbsp;passed&nbsp;the&nbsp;test"&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;确定有多少人考试挂了&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;count_if(vecTestScore.begin(),&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vecTestScore.end(),&nbsp;failed_test)&nbsp;&lt;&lt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;out&nbsp;of&nbsp;"&nbsp;&lt;&lt;&nbsp;vecTestScore.size()&nbsp;&lt;&lt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;students&nbsp;failed&nbsp;the&nbsp;test"&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//计算成绩总和&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;total&nbsp;=&nbsp;accumulate(vecTestScore.begin(),&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vecTestScore.end(),&nbsp;0);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;计算显示平均成绩&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;"Average&nbsp;score&nbsp;was&nbsp;"&nbsp;&lt;&lt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(total&nbsp;/&nbsp;(int)(vecTestScore.size()))&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>Allocator（分配器）&nbsp;<BR><BR>Allocator用在模板的初始化阶段，是为对象和数组进行分配内存空间和释放空间操作的模板类。它在各种情况下扮演着很神秘的角色，它关心的是高层内存的优化，而且对黑盒测试来说，使用Allocator是最好的选择。通常，我们不需要明确指明它，因为它们通常是作为不用添加的缺省的参数出现的。如果在专业的测试工作中出现了Allocator，你最好搞清楚它是什么。&nbsp;<BR><BR>Embed&nbsp;Templates（嵌入式模版）和Derive&nbsp;Templates（基模板）&nbsp;<BR><BR>Any&nbsp;way&nbsp;that&nbsp;you&nbsp;use&nbsp;a&nbsp;regular&nbsp;class,&nbsp;you&nbsp;can&nbsp;use&nbsp;an&nbsp;STL&nbsp;class.&nbsp;<BR><BR>每当你使用一个普通的类的时候，你也可以在其中使用一个STL类。它是可以被嵌入的：&nbsp;<BR><BR>class&nbsp;CParam&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;name;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;unit;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;double&gt;&nbsp;vecData;&nbsp;<BR>};&nbsp;<BR><BR>或者将它作为一个基类：&nbsp;<BR><BR>class&nbsp;CParam&nbsp;:&nbsp;public&nbsp;vector&nbsp;&lt;double&gt;&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;name;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;unit;&nbsp;<BR>};&nbsp;<BR><BR>STL模版类作为基类时需要谨慎。这需要你适应这种编程方式。&nbsp;<BR><BR>模版中的模版&nbsp;<BR><BR>为构建一个复杂的数据结构，你可以将一个模板植入另一个模板中（即“模版嵌套”）。一般最好的方法是在程序前面使用typedef关键字来定义一个在另一个模板中使用的模版类型。&nbsp;<BR><BR>//&nbsp;程序：在向量中嵌入向量的演示。&nbsp;<BR>//目的：说明怎样使用嵌套的STL容器。&nbsp;<BR><BR>#include&nbsp;&lt;iostream&gt;&nbsp;<BR>#include&nbsp;&lt;vector&gt;&nbsp;<BR><BR>using&nbsp;namespace&nbsp;std;&nbsp;<BR><BR>typedef&nbsp;vector&nbsp;&lt;int&gt;&nbsp;VEC_INT;&nbsp;<BR><BR>int&nbsp;inp[2][2]&nbsp;=&nbsp;{{1,&nbsp;1},&nbsp;{2,&nbsp;0}};&nbsp;<BR>//&nbsp;要放入模板中的2x2的正则数组&nbsp;<BR><BR>int&nbsp;main(int&nbsp;argc,&nbsp;char*&nbsp;argv[])&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i,&nbsp;j;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vector&nbsp;&lt;VEC_INT&gt;&nbsp;vecvec;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;如果你想用一句话实现这样的嵌套，你可以这样写：&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;vector&nbsp;&lt;vector&nbsp;&lt;int&gt;&nbsp;&gt;&nbsp;vecvec;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;将数组填入向量&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;VEC_INT&nbsp;v0(inp[0],&nbsp;inp[0]+2);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;传递两个指针&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;将数组中的值拷贝到向量中&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;VEC_INT&nbsp;v1(inp[1],&nbsp;inp[1]+2);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vecvec.push_back(v0);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;vecvec.push_back(v1);&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(i=0;&nbsp;i&lt;2;&nbsp;i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(j=0;&nbsp;j&lt;2;&nbsp;j++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;vecvec[i][j]&nbsp;&lt;&lt;&nbsp;"&nbsp;";&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&lt;&nbsp;endl;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;<BR>}&nbsp;<BR><BR>//&nbsp;输出：&nbsp;<BR>//&nbsp;1&nbsp;1&nbsp;<BR>//&nbsp;2&nbsp;0&nbsp;<BR><BR>虽然在初始化时很麻烦，一旦你将数据填如向量中，你就实现了一个变长的可扩充的二维数组（大小可扩充直到使用完内存）。根据实际需要，可以使用各种容器的嵌套组合。&nbsp;<BR><BR>总结&nbsp;<BR><BR>STL是有用的，但是使用过程中的困难和麻烦是再所难免的。就像中国人所说的：“如果你掌握了它，便犹如虎添翼。”&nbsp;<BR><BR>相关链接<BR>Josuttis&nbsp;Website&nbsp;：</FONT><A href="http://www.blogcn.com/images/aurl.gif" target=_blank><FONT size=1><IMG onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 alt=::URL:: hspace=2 src="http://www.blogcn.com/images/aurl.gif" onload="java_script_:if(this.width>500)this.width=500" align=absBottom border=0></FONT></A><A href="http://www.josuttis.com/" target=_blank><FONT size=1>http://www.josuttis.com/</FONT></A><FONT size=1> &nbsp;<BR>Pretty&nbsp;Good&nbsp;Initialization&nbsp;Library&nbsp;：</FONT><A href="http://www.blogcn.com/images/aurl.gif" target=_blank><FONT size=1><IMG onmousewheel="return bbimg(this)" title=点击在新窗口查看原始图片 alt=::URL:: hspace=2 src="http://www.blogcn.com/images/aurl.gif" onload="java_script_:if(this.width>500)this.width=500" align=absBottom border=0></FONT></A><A href="http://www.codeproject.com/vcpp/stl/PGIL.asp" target=_blank><FONT size=1>http://www.codeproject.com/vcpp/stl/PGIL.asp</FONT></A><FONT size=1> <BR></FONT></P></TD></TR></TBODY></TABLE>]]></description>
</item><item>
<title><![CDATA[Visual C++对大型数据文件的读取]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=ShM1|y_sun&amp;id=16297</link>
<author>ShM1|y_sun</author>
<pubDate>2006/7/5 17:26:52</pubDate>
<description><![CDATA[<SPAN class=top11>问题是这样的，有一批数据文件，数据格式如下：<BR><BR>日期,开盘,最高,最低,收盘,成交量,成交金额<BR><BR>1996年5月13日,636.96,636.96,636.96,636.96,0,0,<BR><BR>1996年5月14日,641.61,641.61,641.61,641.61,0,0,<BR><BR>1996年5月15日,637.83,637.83,637.83,637.83,0,0,<BR><BR>.............<BR><BR>要求将数据填写到四张表中，以便作相应的分析。笔者开始用CFile和CStdioFile类的方法读取件。Cfile类提供了基于二进制流的文件操作，功能类似于C语言中的fread（）和fwrite（）函数。CStdioFile提供了基于字符串流的文件操作，功能类似于C语言中fgets（）和fputs（）函数。但是笔者发现，使用这两个类进行文件操作时，对于一次文件读写的数据量的大小必须限制在65535字节以内。究其原因是在VC中访问大于65535字节的缓冲区需要Huge型指针，而在CFile和CStdioFile类中，使用的是Far型的指针。由于Far型指针不具有跨段寻址的能力，因此限制了一次文件读写的长度小于65535字节。如果传递给CFile和CStdioFile两个类的成员函数的数据缓冲区的大小大于65535字节的时候，VC就会产生ASSERT错误。<BR><BR>针对文件格式特点，改用CArchive类进行读取如下：<BR><BR>CFile SourceFile;//数据文件<BR><BR>CString SourceData;//定义一临时变量保存一条记录<BR><BR>SourceFile.Open(.......);<BR><BR>CArchive ar(&amp;SourceFile,CArchive::load);<BR><BR>while(NULL!=ar.ReadString(SourceData))//循环读取文件，直到文件结束<BR><BR>{<BR><BR>if(SourceData=="日期,开盘,最高,最低，收盘,成交量,成交金额"||SourceData=="")<BR><BR>continue;//跳过文件头部的提示信息<BR><BR>//分析并填充//<BR><BR>}<BR><BR>在进行分析时，笔者采取了逐步分析并修改的办法，过程如下：<BR><BR>int nYear;<BR><BR>CString Year= SourceData.Left(SourceData.Find("年"));//截取年前面的字符串<BR><BR>nYear=atoi(Year);//类型转换<BR><BR>SourceData=SourceData.Righ(SourceData.GetLength()-SourceData.Find("年")-2);//将年以及前面的字符删除。<BR><BR>重复上面分析过程，直到记录末尾。<BR><BR>通过上述方法成功地将文件读取并分析填充。 <BR><BR></SPAN>]]></description>
</item>
</channel>
</rss>