Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HeapSort
#include<stdio.h> #define MAX 100 void build_Heap(int [],int); void HeapSort(int H[],int n); int main() { int arr[MAX],n,i; printf("Enter the total number of array elements: "); scanf("%d",&n); printf("Enter the array elements: "); for(i=1;i<=n;i++) scanf("%d",&arr[i]); HeapSort(arr,n); printf("The sorted array is: "); for(i=1;i<=n;i++) { printf("\t%d",arr[i]); } return 0; } void build_Heap(int H[],int n) { int i,j,k,v,heap; for(i=n/2;i>=1;i--) { k=i; v=H[k]; heap=0; while(heap==0 && (2*k)<=n) { j=2*k; if(j<n) { if(H[j]<H[j+1]) j++; } if(v>=H[j]) heap=1; else { H[k]=H[j]; k=j; } } H[k]=v; } } void HeapSort(int H[],int n) { int t,i; for(i=n;i>=1;i--) { build_Heap(H,i); t=H[1]; H[1]=H[i]; H[i]=t; } }
run
|
edit
|
history
|
help
0
función free()
C/Assembly
18BCE2182 LAB FAT-2(A)-(i)
Búsqueda binaria rec
Difference between memcpy n strncpy
2.1.3 Sum of squares of first hundred natural numbers with different cores
Ad
6 ejercicio trabajo semanal 4
My first array
C_141210_esMayor