<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>评论：堆排序(Heap Sort) 算法实现 C语言版</title>
	<atom:link href="http://www.slyar.com/blog/slyar-heap-sort-c.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.slyar.com/blog/slyar-heap-sort-c.html</link>
	<description>Beijing Normal University Zhuhai Campus</description>
	<lastBuildDate>Sat, 20 Mar 2010 09:11:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>来自：Slyar</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-8743</link>
		<dc:creator>Slyar</dc:creator>
		<pubDate>Wed, 18 Nov 2009 04:34:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-8743</guid>
		<description>&lt;a href=&quot;#comment-8742&quot; rel=&quot;nofollow&quot;&gt;@Yao &lt;/a&gt;没错...好吧，我把代码统一了...</description>
		<content:encoded><![CDATA[<p><a href="#comment-8742" rel="nofollow">@Yao </a>没错...好吧，我把代码统一了...</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Yao</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-8742</link>
		<dc:creator>Yao</dc:creator>
		<pubDate>Wed, 18 Nov 2009 03:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-8742</guid>
		<description>&lt;a href=&quot;#comment-4481&quot; rel=&quot;nofollow&quot;&gt;@Slyar  &lt;/a&gt; 
不好意思，昨天灌了下水;-)
“ki≤K2i且ki≤K2i+1 或  Ki≥K2i且ki≥K2i+1(1≤i≤ n)”
这里的i是从1开始计。
但i在代码中从0开始计，这样 “child=2*i;”似乎应该改为child=2*i+1，∵2*i并非i左孩子（可以画出一棵树进行验证），而“for (i=n/2;i&gt;=0;i--) /* 建立初始堆 */”中改为i=n/2-1。
不知道我理解是否有误？</description>
		<content:encoded><![CDATA[<p><a href="#comment-4481" rel="nofollow">@Slyar  </a><br />
不好意思，昨天灌了下水;-)<br />
“ki≤K2i且ki≤K2i+1 或  Ki≥K2i且ki≥K2i+1(1≤i≤ n)”<br />
这里的i是从1开始计。<br />
但i在代码中从0开始计，这样 “child=2*i;”似乎应该改为child=2*i+1，∵2*i并非i左孩子（可以画出一棵树进行验证），而“for (i=n/2;i&gt;=0;i--) /* 建立初始堆 */”中改为i=n/2-1。<br />
不知道我理解是否有误？</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Yao</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-8741</link>
		<dc:creator>Yao</dc:creator>
		<pubDate>Tue, 17 Nov 2009 10:59:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-8741</guid>
		<description>已阅。</description>
		<content:encoded><![CDATA[<p>已阅。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Slyar</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-6443</link>
		<dc:creator>Slyar</dc:creator>
		<pubDate>Fri, 24 Apr 2009 06:26:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-6443</guid>
		<description>@, 每次删除堆顶元素后难道不需要重新维护堆么？</description>
		<content:encoded><![CDATA[<p>@, 每次删除堆顶元素后难道不需要重新维护堆么？</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：匿名</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-6440</link>
		<dc:creator>匿名</dc:creator>
		<pubDate>Fri, 24 Apr 2009 06:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-6440</guid>
		<description>楼上的代码有问题。。。。。。
堆排每次应该对于堆顶元素进行删除。。。。而不是重新建立一个堆。。。</description>
		<content:encoded><![CDATA[<p>楼上的代码有问题。。。。。。<br />
堆排每次应该对于堆顶元素进行删除。。。。而不是重新建立一个堆。。。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Slyar</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-4481</link>
		<dc:creator>Slyar</dc:creator>
		<pubDate>Wed, 11 Feb 2009 09:00:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-4481</guid>
		<description>@闲人, a[0]</description>
		<content:encoded><![CDATA[<p>@闲人, a[0]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：闲人</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-4479</link>
		<dc:creator>闲人</dc:creator>
		<pubDate>Wed, 11 Feb 2009 08:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-4479</guid>
		<description>你这是从a[0]还是从a[1]开始的啊</description>
		<content:encoded><![CDATA[<p>你这是从a[0]还是从a[1]开始的啊</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：felix021</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1477</link>
		<dc:creator>felix021</dc:creator>
		<pubDate>Sat, 25 Oct 2008 10:25:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1477</guid>
		<description>堆排是O(nlogn)。。。</description>
		<content:encoded><![CDATA[<p>堆排是O(nlogn)。。。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：And You</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1474</link>
		<dc:creator>And You</dc:creator>
		<pubDate>Sat, 25 Oct 2008 02:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1474</guid>
		<description>哦，那就用快排！~~
好像快排更复杂！</description>
		<content:encoded><![CDATA[<p>哦，那就用快排！~~<br />
好像快排更复杂！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Slyar</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1472</link>
		<dc:creator>Slyar</dc:creator>
		<pubDate>Sat, 25 Oct 2008 02:44:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1472</guid>
		<description>汗。。。有些题你不用堆排是会超时的。。。</description>
		<content:encoded><![CDATA[<p>汗。。。有些题你不用堆排是会超时的。。。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Slyar</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1471</link>
		<dc:creator>Slyar</dc:creator>
		<pubDate>Sat, 25 Oct 2008 02:43:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1471</guid>
		<description>呃。。。我空间不大，为了节省数据库。。。囧。。。</description>
		<content:encoded><![CDATA[<p>呃。。。我空间不大，为了节省数据库。。。囧。。。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：And You</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1470</link>
		<dc:creator>And You</dc:creator>
		<pubDate>Sat, 25 Oct 2008 02:42:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1470</guid>
		<description>呵呵，你的博客怎么不管大多少打空格都会省略空格？？
改进会好些啊！</description>
		<content:encoded><![CDATA[<p>呵呵，你的博客怎么不管大多少打空格都会省略空格？？<br />
改进会好些啊！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：And You</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1469</link>
		<dc:creator>And You</dc:creator>
		<pubDate>Sat, 25 Oct 2008 02:41:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1469</guid>
		<description>同上，的确，你的代码能不能打空格呢？？
期待啊！


我一般不用堆排，一是有些慢，二是太麻烦。
我用快速排序或选择排序。
虽然选择排序和堆排一样慢都是O(n^2)的。
选择排序：
#include&quot;stdio.h&quot;
#include&quot;conio.h&quot;
void selectSort(int a[],int count)
{
  int i,j,min,temp;
  for(i=0;i&lt;count-1;i++)
  {
     min=i;
     for(j=i+1;j&lt;count;j++)
       if(a[j]&lt;a[min])
           min=j;
     if(min!=i)
     {
       temp=a[min];
       a[min]=a[i];
       a[i]=temp;
     }
   }
}
void main()
{
  int a[7]={8,9,3,5,1,6,4};
  int i;
  selectSort(a,7);
  clrscr();
  for(i=0;i&lt;7;i++)
    printf(&quot;%4d&quot;,a[i]);
}</description>
		<content:encoded><![CDATA[<p>同上，的确，你的代码能不能打空格呢？？<br />
期待啊！</p>
<p>我一般不用堆排，一是有些慢，二是太麻烦。<br />
我用快速排序或选择排序。<br />
虽然选择排序和堆排一样慢都是O(n^2)的。<br />
选择排序：<br />
#include"stdio.h"<br />
#include"conio.h"<br />
void selectSort(int a[],int count)<br />
{<br />
  int i,j,min,temp;<br />
  for(i=0;i&lt;count-1;i++)<br />
  {<br />
     min=i;<br />
     for(j=i+1;j&lt;count;j++)<br />
       if(a[j]&lt;a[min])<br />
           min=j;<br />
     if(min!=i)<br />
     {<br />
       temp=a[min];<br />
       a[min]=a[i];<br />
       a[i]=temp;<br />
     }<br />
   }<br />
}<br />
void main()<br />
{<br />
  int a[7]={8,9,3,5,1,6,4};<br />
  int i;<br />
  selectSort(a,7);<br />
  clrscr();<br />
  for(i=0;i&lt;7;i++)<br />
    printf("%4d",a[i]);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：felix021</title>
		<link>http://www.slyar.com/blog/slyar-heap-sort-c.html/comment-page-1#comment-1389</link>
		<dc:creator>felix021</dc:creator>
		<pubDate>Sat, 18 Oct 2008 15:07:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.slyar.com/blog/?p=409#comment-1389</guid>
		<description>没有缩进的代码看起来太痛苦。</description>
		<content:encoded><![CDATA[<p>没有缩进的代码看起来太痛苦。</p>
]]></content:encoded>
	</item>
</channel>
</rss>
