Check this case.
6 9 english -1 3 graphics -1 6 mathematics -1
You code should be throwing a
SIGSEGV for this test case. (But it is not, and I don’t know why!)
The idea is this. First, you add a book. Then, you take it out. After this point, in your code, value of
-1. Now, you add another book on to the pile. In your code, the check
if(l<=b[i].serial) will execute. But
b[-1] is undefined. This should have thrown a
Try making sufficient changes to handle the case, when you are adding a book on top of an empty pile. This might be the reason.
Programming Tip: Try indenting your code. It is easy to understand/debug.