Beruflich Dokumente
Kultur Dokumente
#include<stdio.h>
#include<conio.h>
void crheap(int [], int);
void processheap(int [],int);
int main(void)
{
int k[50],small,big,q,key,n,t,i;
clrscr();
#include <stdio.h>
int main(void) {
int clrscr();
int n;
int k[100];
int i;
printf("\n enter the no. of elements: ");
scanf(" %d",&n);
printf("\n Now enter the array elements: ");
for(i=1;i<=n;i++)
{scanf(" %d",&k[i]);}
crheap(int k,int n);
int processheap(int k,int n);
return(0);
}
void int crheap(int k[],int n)
{
int i,q, big,small,temp;
for(q=2;q<=n;q++)
{
small=q;
big=(int)small/2;
while(small >1 && k[small] > k[big])
{
temp=k[small];
k[small]= k[big];
k[big]=temp;
small=big;
big=(int)small/2;
if(big < 1)
big=1;
}
}
printf("\n Now the array in heap form is: ");
for(i=1;i<=n;i++)
printf(" %3d",k[i]);
}
return 0;
}
return 0;
}
(b)
/* heapsort function */