int main() { srand((unsigned int)time(NULL)); int n,*H,N1=0,N2=0,M; int i=0,x; printf("n="); scanf("%d",&n); H=(int *)malloc(n*sizeof(int)); printf("\n\n+++ MedHeap initialized"); printf("\n\n+++ Going to insert elements one by one in MedHeap"); for(i=0;i<n;i++) { x=rand()%30000; printf("\nInsert(%d) done.",x); insertMed(H,n,N1,N2,x); M=findMedian(H,n,N1,N2); printf("Current Median=%d.",M); } MedHeapSort(H,n,N1,N2); printf("\n+++ Median Heap Sort done\n"); for(i=0;i<n;i++) printf("%d ",H[i]); return 0; }
int main() { int n=200000,H[200000],N1=0,N2=0,M; int i=0,x; char s[1000]; scanf("%s",s); while(s[0]!='E') { if(s[0]=='A'){scanf("%d",&x);insertMed(H,n,N1,N2,x);} if(s[0]=='M'){printf("%d\n",findMedian(H,n,N1,N2));} scanf("%s",s); } return 0; }