<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>一花一世界 &#187; Sorting</title>
	<atom:link href="http://www.juliuschen.com/archives/category/algorithm/sorting/feed" rel="self" type="application/rss+xml" />
	<link>http://www.juliuschen.com</link>
	<description>谈笑间，樯橹灰飞烟灭</description>
	<lastBuildDate>Sun, 29 Aug 2010 10:32:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>基数排序</title>
		<link>http://www.juliuschen.com/archives/15.html</link>
		<comments>http://www.juliuschen.com/archives/15.html#comments</comments>
		<pubDate>Fri, 25 Dec 2009 09:54:43 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[基数排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[非比较排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/15</guid>
		<description><![CDATA[基数排序和计数排序一样，是非基于比较的排序算法，它借助“分配”和“收集”两种操作对单逻辑关键字进行排序（基于箱/桶排序），它的排序速度很快，时间复杂度为线性，但由于需要的辅助空间太大（n(radix+1)），因此长期无法应用。直到1954年有人提出用“计数”代替“分配”才得以使它能在计算机上实现。此后，又有人提出用链表作为存储数据的结构，这样又能减少一些辅助空间，这也是一种比较好的实现方法（只是算法要较复杂）。 基数排序分为MSD（最高位优先）基数排序和LSD（最低位优先）基数排序，MSD从左到右处理关键字的位数，首先处理最重要的数字。它比较符合常规的思维，所需处理的信息量也较少。但按MSD进行排序，必须将序列逐层分割成若干个子序列，然后对各子序列分别进行排序；而LSD则从右到左先处理最不重要的数字，这样虽然可能花费了一些时间来处理不会影响结果的信息，但它不用分子序列，对每个关键字都是整个序列参加排序，而且对具体的应用还可以对其进行改进。因此在很多排序应用中都选择这种方法。 基数排序（LSD/用计数排序）的C/C++代码实现： void radix_sort(int a[], int length) { &#160; &#160; int&#160;i, j, digit; &#160; &#160; int&#160;c[16]; &#160; &#160; int&#160;temp[ARRAY_SIZE]; &#160; &#160; for&#160;(i = 0; i &#60; HEX; ++i) { &#160; &#160; &#160; &#160; for&#160;(j = 0; j &#60; 16; ++j) c[j] = 0; &#160; &#160; &#160; &#160; for&#160;(j = 0; j &#60; length; ++j) [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/15.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>计数排序</title>
		<link>http://www.juliuschen.com/archives/14.html</link>
		<comments>http://www.juliuschen.com/archives/14.html#comments</comments>
		<pubDate>Thu, 24 Dec 2009 10:34:17 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[计数排序]]></category>
		<category><![CDATA[非比较排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/14</guid>
		<description><![CDATA[计数排序(Counting Sort)是一种非基于比较的排序方法，它要求所有的待排元素都必须是≥0的整数。它的排序步骤是首先根据数组中最大的元素值加1作为长度来定义一个计数数组C。然后统计待排数组中每个值为i的元素出现的次数，存入C的第i项中。再对所有的计数累加（从C中的第一项开始，每一项和前一项相加）。最后再反向填充辅助数组：将每个元素i放在辅助数组的第C(i)项，每放一个元素就将C(i)减去1。这样完成之后排序就已完毕，有序序列已存储在辅助数组中。如果结果想用原数组输出，则将它们从辅助数组考回到原数组即可。 计数排序的C/C++代码实现： void counting_sort(int a[], int length) { &#160; &#160; int&#160;i; &#160; &#160; int&#160;c[MAX_VALUE] = {0}; &#160; &#160; int&#160;temp[ARRAY_SIZE] = {0}; &#160; &#160; for&#160;(i = 0; i &#60; length; ++i) c[a[i]]++; &#160; &#160; for&#160;(i = 1; i &#60; MAX_VALUE; ++i) c[i] += c[i-1]; &#160; &#160; for&#160;(i = length - 1; i &#62;= 0; --i) [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/14.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>归并排序</title>
		<link>http://www.juliuschen.com/archives/13.html</link>
		<comments>http://www.juliuschen.com/archives/13.html#comments</comments>
		<pubDate>Tue, 22 Dec 2009 10:27:11 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[归并排序]]></category>
		<category><![CDATA[排序算法]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/13</guid>
		<description><![CDATA[归并排序是建立在归并操作（Merging）上的一种排序方法，它是采用分治法的一个非常典型的应用。归并是指将两个或两个以上的有序表合并成一个新的更大的有序表，归并排序则是递归的先将待排序列分割成n个序列，然后从最小的有序序列（只含一个元素）开始不断调用归并操作进行合并直到最后都合并成一个大的完整的有序表为止。 归并排序的C/C++代码实现： void merge(int array[], int low, int m, int high) { &#160; &#160; int&#160;i, j, k; &#160; &#160; static&#160;int temp[ARRAY_SIZE]; &#160; &#160; for&#160;(i = low, j = m + 1, k = 0; k &#60; high - low + 1; ++k) { &#160; &#160; &#160; &#160; if&#160;(i &#62; m) { &#160; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/13.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>堆排序</title>
		<link>http://www.juliuschen.com/archives/12.html</link>
		<comments>http://www.juliuschen.com/archives/12.html#comments</comments>
		<pubDate>Mon, 21 Dec 2009 10:12:45 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[堆排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[选择排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/12</guid>
		<description><![CDATA[堆排序是对树形选择排序的改进，它首先将整个待排序列构建成一个堆，然后将堆顶元素与最后一个元素交换，由此得到一个有序元素和一个长度减1的堆。由于交换后新的堆顶元素可能不满足堆的定义，因此需要将新的堆重新进行堆化（堆化无需重新建堆，只需做少许调整），在堆化完成之后再次将堆顶元素与堆的最后一个元素交换，由此再得到一个新的有序元素和一个长度减1的堆。然后再重新进行堆化，再交换。。。这样一直下去，直到整个堆只有一个元素为止。这样也就完成了对序列的排序。由这个排序的过程也可以知道，堆排序和简单选择排序不同，不是从前往后慢慢有序，而是从后往前慢慢有序。 堆排序的C/C++代码实现： void heapify(int sort_array[], int k, int m) { &#160; &#160; int&#160;temp = sort_array[k]; &#160; &#160; for&#160;(int j = 2 * k; j &#60;= m; j *= 2) { &#160; &#160; &#160; &#160; if&#160;(j &#60; m &#38;&#38; sort_array[j] &#60; sort_array[j+1]) ++j; &#160; &#160; &#160; &#160; if&#160;(!(temp &#60; sort_array[j])) break; &#160; &#160; &#160; &#160; sort_array[k] [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>快速排序</title>
		<link>http://www.juliuschen.com/archives/11.html</link>
		<comments>http://www.juliuschen.com/archives/11.html#comments</comments>
		<pubDate>Sun, 20 Dec 2009 07:50:37 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[交换排序]]></category>
		<category><![CDATA[快速排序]]></category>
		<category><![CDATA[排序算法]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/11</guid>
		<description><![CDATA[快速排序是应用最广泛的排序算法，也是目前认为最好的一种内部排序方法（就平均时间而言）。它采用分治（divide-and-conquer）的策略，通过一趟排序将待排记录分割成独立的两个部分，使其中的一部分记录关键字均比另一部分记录关键字小（大），然后分别对两个部分继续进行排序，以达到整个序列有序。 快速排序的C/C++代码实现： int partition(int sort_array[], int low, int high) { &#160; &#160; int&#160;pivotkey = sort_array[low]; &#160; &#160; while&#160;(low &#60; high) { &#160; &#160; &#160; &#160; while&#160;(low &#60; high &#38;&#38; pivotkey &#60;= sort_array[high]) --high; &#160; &#160; &#160; &#160; sort_array[low] = sort_array[high]; &#160; &#160; &#160; &#160; while&#160;(low &#60; high &#38;&#38; pivotkey &#62;= sort_array[low]) ++low; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/11.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>希尔排序</title>
		<link>http://www.juliuschen.com/archives/10.html</link>
		<comments>http://www.juliuschen.com/archives/10.html#comments</comments>
		<pubDate>Tue, 15 Dec 2009 12:37:25 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[希尔排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[插入排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/10</guid>
		<description><![CDATA[希尔排序是插入排序的扩展。希尔排序的一个特点是：子序列的构成不是简单的逐段分割，而是将相隔某个增量的记录组成一个子序列。希尔排序的一个关键是：其步长（也就是增量）的取法，通常认为步长序列中的数字互质很重要。 希尔排序的C/C++代码实现： void shell_insert(int sort_array[], int length, int h) { &#160; &#160; int&#160;i, j, temp; &#160; &#160; for&#160;(i = h; i &#60; length; ++i) &#160; &#160; &#160; &#160; if&#160;(sort_array[i] &#60; sort_array[i-h]) { &#160; &#160; &#160; &#160; &#160; &#160; temp = sort_array[i]; &#160; &#160; &#160; &#160; &#160; &#160; sort_array[i] = sort_array[i-h]; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/10.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>简单排序方法</title>
		<link>http://www.juliuschen.com/archives/9.html</link>
		<comments>http://www.juliuschen.com/archives/9.html#comments</comments>
		<pubDate>Mon, 14 Dec 2009 15:03:55 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[交换排序]]></category>
		<category><![CDATA[冒泡排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[插入排序]]></category>
		<category><![CDATA[直接插入排序]]></category>
		<category><![CDATA[简单选择排序]]></category>
		<category><![CDATA[选择排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/9</guid>
		<description><![CDATA[简单的排序方法主要是指直接插入排序、冒泡排序和简单选择排序。他们都是稳定的排序方法，平均时间复杂度都为O(n2)，并且空间复杂度都为O(1)。 直接插入排序 直接插入排序（Straight Insertion Sort）是一种最简单的排序方法，它的基本操作是将一个记录插入到已排好序的有序表中，从而得到一个新的、记录数增1的有序表。直接插入排序的运行时间和数据原始排列顺序密切相关。对于已经排好序（或已几乎排好序）的数据，插入排序的效率会比较高。 直接插入排序的C/C++代码实现： void insert_sort(int sort_array[], int length) { &#160; &#160; int&#160;i, j; &#160; &#160; for&#160;(i = 2; i &#60; length; ++i) &#160; &#160; &#160; &#160; if&#160;(sort_array[i] &#60; sort_array[i-1]) { &#160; &#160; &#160; &#160; &#160; &#160; sort_array[0] = sort_array[i]; &#160; &#160; &#160; &#160; &#160; &#160; sort_array[i] = sort_array[i-1]; &#160; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
