Page 250 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 250
Unit 13: Sorting
if(child+1<=N-1 && (v[child+1]>v[child])) Notes
child++;
if (v[parent]< v[child])
{
int aux=v[parent];
v[parent]=v[child];
v[child]=aux;
parent=child;
child=2*parent+1;}
else
break;
}
return a;
}
void heap_sort(int a[], int N, int v[])
{
for(int i=N-1; i>=0; i—)
{
N=i+1;
a[i]=remove(v,N);
}
}
void heap_gen1(int a[], int v[], int n)
{
int N=1;
v[0]=a[0];
for(int i=1; i< n; i++)
{
insert(v, N, a[i]);
}
}
void display(int a[], int n)
{
for(int i=0; i<n; i++)
{
cout << a[i] << “ ”;
}
}
int main()
{
int *a=new int[100];
int *v=new int[100];
LOVELY PROFESSIONAL UNIVERSITY 243