#include "stdio.h"
#include "Stdlib.h"
void swap (int *a,int *b)//Exchange two numbers
{
int t;
T=*a;
*a=*b;
*b=t;
}
void minheap (int *a,int i)//Keng Gen adjustment, in the I-node upward adjustment, based on a given array, the creation of small Gan for the arrays
{
int temp,j;
Temp=a[i];
j= (i-1)/2; The parent node of the I node
while (j>=0&&i!=0)
{
if (a[j]<temp) break;
A[I]=A[J];
I=j;
j= (i-1)/2;
}
A[i]=temp;
}
void Add (int *a,int key,int N)//insert a node at the end and make an adjustment
{
A[n]=key;
Minheap (A,n);
}
void Minheapfix (int *a,int i,int N)//adjustment after deleting node I
{
int j,temp;
Temp=a[i];
j=2*i+1;
while (J<n)
{
if (J+1<n&&a[j+1]<a[j])
j + +;
if (a[j]>temp) break;
A[I]=A[J];
I=j;
j=2*i+1;
}
A[i]=temp;
}
void Deletenumber (int a[],int n)//Delete last node
{
Swap (&a[0],&a[n-1]);
Minheapfix (a,0,n-1);
}
void sort (int a[],int n)//Sort small Gan, small Gan a[0] is the minimum value, each time and the last node is interchanged, then the heap is adjusted, and so on
{
for (int i=n-1;i>=1;i--)
{
Swap (&a[i],&a[0]);
Minheapfix (A,0,i);
}
}
int main ()
{
int a[7]={2,3,4,2,5,6,3},i;
for (i=0;i<7;i++)
Add (a,a[i],i);
Sort (a,7);
for (i=0;i<7;i++)
printf ("%d", a[i]);
return 0;
}
C Language implementation of heap creation in data structures, heap sequencing