Why pop operation in Stack using Array has flaw?
if take an example of implementation of data structure Stack using array there are some obvious flaw.
Let’s take the POP operation of the stack. The algorithm would go something like this.
- Check for the stack underflow
- Decrement the top by 1
So there what we are doing is that, the pointer to the topmost element is decremented means we are just bounding our view actually that element stays there talking up of the memory space. If you have any primitive datatype then it might be ok but the object of an array would take a lot of memory.