I've been told that the following code has an efficiency O(1):
void mystack::Pop_element()
{
assert ( nelem > 0 );
nelem--;
if ( nelem < reserved / 4 ){
Resize ( reserved / 2 );
}
}
But I don't really understand why, since Resize has an efficiency O(n) (that is a fact, we aren't supposed to know the code inside Resize). So, shouldn't the whole code have O(n) efficiency as well?