A stack is implemented with an array of ‘A[0…N – 1]’ and a variable ‘pos’. The push and pop operations are defined by the following code.
push (x) A[pos] ← x pos ← pos – 1end pushpop ( ) pos ← pos + 1 return A[pos]end pop
Which of the following will initialize an empty stack with capacity N for the above implementation ?
(A) pos ← –1
(B) pos ← 0
(C) pos ← 1
(D) pos ← N – 1
Home Modern › Forums › ISRO › A stack is implemented with an array of ‘A[0…N – 1]’ and a variable ‘pos’. The push and pop operations are defined by the following code. Which of the following will initialize an empty stack with capacity N for the above implementation ? A stack is implemented with an array of ‘A[0…N – 1]’ and a variable ‘pos’. The push and pop operations are defined by the following code. Which of the following will initialize an empty stack with capacity N for the above implementation ?push (x) A[pos] ← x pos ← pos – 1end pushpop ( ) pos ← pos + 1 return A[pos]end pop
(A) pos ← –1
(B) pos ← 0
(C) pos ← 1
(D) pos ← N – 1push (x) A[pos] ← x pos ← pos – 1end pushpop ( ) pos ← pos + 1 return A[pos]end pop
(A) pos ← –1
(B) pos ← 0
(C) pos ← 1
(D) pos ← N – 1
nan