If stack is an array that contains the entries in a stack, what is a disadvantage of maintaining the top entry of the stack in stack[0]?
The array has a definite size so does the stack which is to be implemented. So every time we push an element in the stack it is stored as the first element of stack and if we push any element when the stack size if full it will give us an exception.We have to know the upper bound of growth and allocate memory accordingly.
As you know the stack fill its elements from back so first nth index will fill then n-1th ...... then 1st then 0th index. So stack[0] will only be happen when there are atleast n elements pushed in the stack.
Get Answers For Free
Most questions answered within 1 hours.