#include<stdio.h>
#include<algorithm>
using namespace std;
int heap_size1,heap_size2;
int main()
{
int n,a[100],j,k;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
if(n%2)
{
heap_size2=n/2+1;
k=n-1;
}
else
{
heap_size2=n/2;
k=n;
}
heap_size1=n/2;
for(j=1;j<k;j+=2,k-=2) // diving even positions
and odd positions of array with even elements at partition1 and odd elements
at partition2
swap(a[k],a[j]);
heapsort(a,1,heap_size1); // where 1-> for root
of heap1 ; Use min heap for sorting
inverse_heapsort(a,heap_size1+1,heap_size2); //where heap_size1+1
-> for root of heap2 ; use max heap for sorting
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
return 0;
}
Cheers
~ Jeeva ~
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.