A stack is a linear list in which insertion and removals take place at one end called top of the stack. (OR)
A stack is an ordered collection of homogeneous data elements where the insertion and deletion take place at one end only.
·
·
- A stack is a linear data structure.
- The insertion operation is called push operation and delectation operation is called pop operation.
- The following are different statuses of stack, when stack contain ‘N’ elements
- When the stack is empty, trying to perform pop() operation causes an exception “StackUnderFlow”
- When the stack is full, trying to perform push() operation causes an exception “StackUnderFlow”
- When push() operation is performed ‘top’ will be incremented by one; similarly when pop() is performed ‘top’ is decremented by one.
- ‘top’ is a pointer which indicates the status of stack and topmost element on stack.
A stack is an abstract data type that supports following methods
AbstractDataType stack
{
Instances: Linear list of elements; one end is called the bottom; and other is the top
Operations:
Stack(): creates a new stack that is empty. It needs no parameters and returns an empty stack.
push(item): adds a new item to the top of the stack. It needs the item and returns nothing.
pop(): removes the top item from the stack. It needs no parameters and returns the item.
The stack is modified.
peek(): returns the top item from the stack but does not remove it. It needs no parameters.
The stack is not modified.
isEmpty(): tests to see whether the stack is empty. It needs no parameters and returns a Boolean value.
size(): returns the number of items on the stack. It needs no parameters and returns an integer.
}
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.