0

program of strack

--------------------------------------------------------------------------------

Hi,
I,m Arvind .I have problem in stack programming,please tell me how to
enter no's in a stack and how to check for overflow & underflow using push &
pop function. arizona

3
Contributors
2
Replies
3
Views
13 Years
Discussion Span
Last Post by Narue
0

Okay, first you need to decide how to represent the stack. A stack is an abstraction that can be represented a number of ways, the most common being either an array or a linked list.

>please tell me how to enter no's in a stack
This would be the push operation. It's very simple using either an array or a linked list. Simply add the number to the end of the array and increment the top index for an array based implementation, or insert a new node at the front of the list for a list based implementation.

>and how to check for overflow & underflow using push & pop function.
For an array based implementation, if the top index is 0 then the stack is empty, if the top index is N then the stack is full. For a list based implementation, if the head node is nil then the list is empty and so is the stack. There is no overflow in a list based implementation except when you run out of some critical resource in creating nodes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.