Computer Science, asked by wwwmuzzaffers7044, 16 days ago

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 farhankaimuri403
36

Answer:

top >= 0

Explanation:

we need to check if stack is empty or not.

Answered by mindfulmaisel
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