CEG's Linux User Group

  • Increase font size
  • Default font size
  • Decrease font size
Home Labs Double-stack implementation

Double-stack implementation

E-mail Print
User Rating: / 8
PoorBest 
Article Index
Double-stack implementation
Source code
Documentation
Test cases
Compatibility
All Pages

DOUBLE STACK - ARRAY IMPLEMENTATION

Introduction :

Double stack means two stacks which are implemented using a single array. To prevent memory wastage, the two stacks are grown in opposite direction. The pointer tops1 and tops2 points to top-most element of stack 1 and stack 2 respectively. Initially, tops1 is initialized as -1 and tops2 is initialized the capacity. As the elements are pushed into stack 1, tops1 is incremented. Similarly, as the elements are pushed into stack 2, tops2 is decremented. So, the array is full when tops1=tops2-1. Beyond this, pushing an element into any stack will lead to overflow condition. The pictorial representation of double stack is shown below.

doublestack



Last Updated on Friday, 05 June 2009 16:56  
Please register or login to add your comments to this article.