push (x)
A[pos] <- x
pos <- pos -1
end push
Look at the push operation. $x$ is pushed at pos
, then pos
is decremented.
This means if our array is $A[0,1,2,3]$ then in order to push four elements, we first we're pushing at index 3, then at index 2, then at index 1 and finally at index 0.
We have to initialize pos
with the value equalling $N-1$
Option D