Program In C:- //Maxheap Sort #include <stdio.h> #include <stdlib.h> #define MAX 20 void maxheapify(int *, int, int); int* buildmaxheap(int *, int); void main() { int i, t, n; int *a = calloc(MAX, sizeof(int)); int *m = calloc(MAX, sizeof(int)); printf("enter no of elements in the array\n"); scanf("%d", &n); printf("enter the array\n"); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } m = buildmaxheap(a, n); printf("the heap is\n"); for (t = 0; t < n; t++) { printf("%d\n", m[t]); } } int* buildmaxheap(int a[], int n) { int heapsize = n; int j; for (j = n/2; j >= 0; j--) { ...
Comments