4. What is stack overflow ?
Pushing elements when stack is full.
When top exceeds size of stack .
5. Algorithm push
Procedure Push (Value)
If TOP is equal to MAX
Output an error that the Stack is full
Else
Add 1 to TOP
Put data in Value into TOP position
End If
End Procedure
6. What is pop ?
Removing the top element from the
stack.
7. What is stack underflow ?
Performing pop operation when a
stack is empty.
When top equals zero.
8. Algorithm pop
Procedure Pop
If TOP is equal to Zero then
Stack is empty “Underflow”
Else
Output value from Stack at TOP position
Subtract 1 from TOP
End If
End Procedure
18. Argument passing in C
• Consider the following program :-
# include <stdio.h>
# include <conio.h>
void main()
{
int a=3;
clrscr();
printf(“%d %d%d%d”,a++,++a,++a,a++);
getch();
}
Expected o/p.
3566
19. But
o/p is 6 6 5 3
Because the argument are passed from
right to left in a stack and then sent to
printf function.
20. %d %d Top
%d %d
6 Called function ie, printf(…);
Here the input is taken from stack
6 So, the data order will be 6 6 5 3.
5 Therefore the o/p will be 6 6 5 3.
3
21. Conclusion
Stack is one of the efficient way to
implement discipline to system.