من در اجرا به مشکل Stack Overflow برمیخورم در خط 27 :
#include<iostream>
#include<conio.h>
using namespace std;
int *a,heap_size,x,largest;
int left(int i)
{
return (2*i)+1;
}
int right(int i)
{
return (2*i)+2;
}
void max_heapfy(int a[],int i)
{
int l,r,largest;
l=left(i);
r=right(i);
if(l<=heap_size && a[l]>a[i])
largest=l;
else
largest=i;
if(r<=heap_size && a[r]>a[largest])
largest=r;
if(largest!=i)
swap(a[i],a[largest]);
max_heapfy(a,largest);
}
void build(int a[])
{
int i;
if(x % 2 ==1)
{
for(i=x/2;i>=0;i--)
max_heapfy(a,i);
}
if(x % 2 ==0)
{
for(i=(x/2)-1;i>=0;i--)
max_heapfy(a,i);
}
}
void main()
{
int *a,i;
cout<<"Enter size of array:\n";
cin>>x;
heap_size=x;
a=new int[x];
cout<<"Enter Numbers for Ordering:\n";
for(i=0;i<x;i++)
cin>>a[i];
build(a);
for(i=0;i<x;i++)
cout<<a[i];
delete []a;
getch();
}