heap sort

hi
i'm trying to implement a version of heap sort, the compiling gives no problem;
however the vector doesn't get sorted.

can somebody help me see where i fail?
here' s my code:

void swap(vector<int>& a,int i,int j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}

void max_heapify(vector<int> &a,int i,int size)
{
int pos_max;
int l,r;
l=2*i+1;
r=2*i+2;

if(l<size && a[l]>a[i])
pos_max=l;
else pos_max=i;
if(r<size && a[r]>a[pos_max])
pos_max=r;
if(i!=pos_max){
swap(a,i,pos_max);
max_heapify(a,pos_max,size);
}
}


void build_max_heap(vector<int>& a,int size)
{

for(int i=size/2;i>=0;i--)
max_heapify(a,i,size);
}


void heapsort(vector<int>&a)
{
int size=a.size();
build_max_heap(a,size);
for(int i=size;i>=2;i--) {
swap(a,1,i);
size=size-1;
max_heapify(a,1,size);
}
}
thanks
Topic archived. No new replies allowed.