| 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.

| < Prev | Next > |
|---|




