Heap sorting.C++ Programming code


void Sift(int b[],int l,int r)
{
int i=l;
int x=b[i];
int j=2*i+1;
if((j<r)&&(b[j]<b[j+1])) j++;
while((j<=r)&&(x<b[j]))
{
b[i]=b[j];
i=j;
j=2*i+1;
if((j<r)&&(b[j]<b[j+1])) j++;
}
if(i!=l) b[i]=x;
}

void HeapSort(int m,int b[])
{
for(int i=m/2-1;i>=0;i–)
Sift(b,i,m-1);
for(i=m-1;i>0;)
{
int x=b[i];
b[i]=b[0];
b[0]=x;
Sift(b,0,–i);
}
}

Advertisements

One Comment to “Heap sorting.C++ Programming code”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: