Median in a running stream

why this is giving segmentation fault

@shampblocks,
Corrected code, here,
Correction, Always explicitly convert *.size() type value into int because by default they are unsigned ints and can give error in arithmetic operations.

1 Like

But sir i have tried without explicitly changing in my previous questions but why there is segmentation fault in this question particularly??

@shampblocks,
You are doing subtraction here, subtraction and unsigned ints, aren’t that friendly you know… :upside_down_face:

Oh great small small things matter thanks sir… And one more doubt sir how that is coming segmentation fault?? It’s a type of segmentation fault??

@shampblocks,
Nope, it does not mean seg error, it only gives wrong subtraction result, which indeed lets the boolean expression inside if be true, which leads to a top() and pop() statement, and toping and hoping from empty queue is set error.

In which boolen expression this popping is happening?? Which was giving error?

@shampblocks,
Any if inside which you had done subtraction of sizes…