Running Median of a stream of intergers

Sir/Ma’am , I tried to run my code on GFG, it showed segmentation fault. I couldn’t figure out why is it so?
could you please help me…
Also if i give the input as 6
1 5 4 3 2 1 the output expected is 1 3 4 3 3 2 but the output coming is 1 3 4 3 3 3 . I couldn’t get why is it coming wrong?
Please tell. Sharing my code: https://ide.codingblocks.com/s/174167

Please reply…

Hello @priyanshi.agarwal3405

Change Line 11 to if(cMax==cMin) from if((cMax+cMin)%2==0)
Let me know if you still need any help.

Sir, changed line 11, and tried to run on gfg, still test cases not passing. Sharing the error what gfg says:: “Wrong Answer. !!!Wrong Answer Possibly your code doesn’t work correctly for multiple test-cases (TCs). The first test case where your code failed: Input: 9384 Its Correct output is: 9384 And Your Code’s output is: 9384 5135 2778 4847 6916 7355 6916 6151 6650 6018 5387…” Could you please tell where am i going wrong??

Sir please reply…

@priyanshi.agarwal3405

Print a endl (and Not a space) after each printing each median

Here is the modified code

okay, got that. Just wanted to ask one more thing why you asked me to change line 11?? I mean why checking for even sum was not working here.

Sir reply please…

@priyanshi.agarwal3405

Let us suppose that
maxHeap is like 1 2 4 5 and minHeap is like 9 8 7 // Here the median is 5
and an element comes in = 3

So now you check if (3 < 5) True, then you push 3 into maxHeap
The maxHeap is now 1 2 3 4 5

The sum of size of maxHeap and minHeap is even but the answer is Not (5 + 7)/2
the answer is (4 + 5)/2

Let me know if you still need any help.

okay, got it … Thank you so much sir!!