The way I see is: something must be buggy, I can't see it working, maybe because I failed to understand the expected input (I just skimmed through the code). I detected LOOOOOTS of potentials for segmentation fault, it's kinda hard to choose where to start to tackle without knowing a case that makes it fail. What input cases have you tested it with? Did it work with your own inputs? Have you tried extreme inputs yourself?
Haven't tried extreme inputs myself But What I tested with was kinda like this Haven't tried extreme example, cuz I can't imagine how to make it. 5 [This is first input] [And this is next input, which have to input 5 samples] push 12 push 8 pop size top