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

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.