#c #arrays #sorting #data-structures #heap
Вопрос:
int swap(int *dum ,int i, int temp)
{
int j=*(dum temp);
*(dum temp)=*(dum i);// swapping numbers in index i and temp of array dum
*(dum i)=j;
return 0;
}
int main()
{
int a[6]={32,40,15,50,5,44};
int n=6;
int *dum=new int[n];
for(int i=0;i<n;i )
{
*(dum i)=*(a i);// assigning input array elements to a dummy error
if(i>0)
{
int temp=(i-1)/2;
while(*(dum i)>*(dum temp))// checking if a particular node is larger than parent node data
{
swap(dum,i,temp);// calling a function to swap the data a indices i and temp
i=temp;// i will now hold the index of parent of previous i
temp=(i-1)/2;//temp will now hold parent of new i
if(i==0)
{
break;
}
}
}
}
for(int i=0;i<n;i )
{
cout<<*(dum i)<<"n";//print data members in dummy array
}
}
ВЫВОД:// это вывод, рядом с ним находится желаемый вывод
50 //50
50 //40
44 //44
50 //32
5 //15
44 //5