A stack is implemented as a linear array A[0...N-1]. A programmer writes thefunction given below to pop out an element from the stack,function POP( top, N){if (X){top=top-1)elseho{print "Underflow"}return top}what should substitute the condition x
Answers
Answered by
36
Answer:
top >= 0
Explanation:
we need to check if stack is empty or not.
Answered by
13
X = top>=0 && top<N
Explanation:
function POP( top, N){
if (X){
top=top-1
}else{
print "Underflow"
}
return top
}
- when we pop from the stack, then the pointer will move one step down.
- So we have to check the border condition that the pointer top is non-negative or not
- and also the top is above the length of the stack or not.
- Thus, X = top>=0 && top<N
Similar questions
History,
1 month ago
Physics,
1 month ago
Computer Science,
2 months ago
Hindi,
2 months ago
Chemistry,
10 months ago
Accountancy,
10 months ago