Stack can be implemented using arrays and pointers.
- Array implementation
- Linked List implementation
1.Array implementation:
In this implementation each stack is associated with a pop pointer which is '-1' for empty stack.
- To push an element X onto the stack, Top pointer is incremented and then set stack[Top]=X.
- To pop an element, the stack[Top] value is returned and the top pointer is decremented.
- Pop on an empty stack (or) push on a full stack will exceed the array bounds.
2. Linked List implementation
- Push operation is performed by inserting an element at front of the list.
- Pop operation is performed by deleting at the front of the list.
- Top operation returns the element at the front of the list.
*************
No comments:
Post a Comment