<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Heap Sort</title>
	<atom:link href="http://programmingpraxis.com/2009/11/06/heap-sort/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/11/06/heap-sort/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Mon, 28 May 2012 03:30:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Vikas Tandi</title>
		<link>http://programmingpraxis.com/2009/11/06/heap-sort/#comment-2947</link>
		<dc:creator><![CDATA[Vikas Tandi]]></dc:creator>
		<pubDate>Fri, 29 Apr 2011 08:07:51 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1589#comment-2947</guid>
		<description><![CDATA[here is my implementation in c
[sourcecode lang=&quot;cpp&quot;]

static void heapify(int arr[], int left, int right);
static void sort(int arr[], int left, int right);
static void siftup(int arr[], int left, int right, int key);

void heapsort(int arr[], int left, int right)
{
	/* transform input file into a heap */
	heapify(arr, (right+1)/2, right+1);

	/* sort the heap */
	sort(arr, left+1, right+1);
}

static void heapify(int arr[], int left, int right)
{
	int i;

	/* convert to heap */
	for(i = left; i &gt; 0; i--)
		siftup(arr, i, right, arr[i-1]);
}

static void sort(int arr[], int left, int right)
{
	int i, key;

	for(i = right; i &gt; 1; i--)
	{
		key = arr[i-1];
		arr[i-1] = arr[left-1];		/* move the biggest element to the rightmost position in array */

		/* move up the next biggest element to root */
		siftup(arr, left, i-1, key);
	}
}

static void siftup(int arr[], int left, int right, int key)
{
	int i, j;

	/* move down the tree */
	for(i = left, j = 2*i;  j &lt;= right; i = j, j = 2*i)
	{
		/* j should point to the largest child */
		if(j &lt; right &amp;&amp; arr[j-1] &lt; arr[j])
			j++;

		/* if child is smaller or equal to parent, than break out of loop */
		if(key &gt;= arr[j-1])
			break;
		
		/* move up the child element */
		arr[i-1] = arr[j-1];
	}
	arr[i-1] = key;
}
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>here is my implementation in c</p>
<pre class="brush: cpp;">

static void heapify(int arr[], int left, int right);
static void sort(int arr[], int left, int right);
static void siftup(int arr[], int left, int right, int key);

void heapsort(int arr[], int left, int right)
{
	/* transform input file into a heap */
	heapify(arr, (right+1)/2, right+1);

	/* sort the heap */
	sort(arr, left+1, right+1);
}

static void heapify(int arr[], int left, int right)
{
	int i;

	/* convert to heap */
	for(i = left; i &gt; 0; i--)
		siftup(arr, i, right, arr[i-1]);
}

static void sort(int arr[], int left, int right)
{
	int i, key;

	for(i = right; i &gt; 1; i--)
	{
		key = arr[i-1];
		arr[i-1] = arr[left-1];		/* move the biggest element to the rightmost position in array */

		/* move up the next biggest element to root */
		siftup(arr, left, i-1, key);
	}
}

static void siftup(int arr[], int left, int right, int key)
{
	int i, j;

	/* move down the tree */
	for(i = left, j = 2*i;  j &lt;= right; i = j, j = 2*i)
	{
		/* j should point to the largest child */
		if(j &lt; right &amp;&amp; arr[j-1] &lt; arr[j])
			j++;

		/* if child is smaller or equal to parent, than break out of loop */
		if(key &gt;= arr[j-1])
			break;
		
		/* move up the child element */
		arr[i-1] = arr[j-1];
	}
	arr[i-1] = key;
}
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

