| Article Index |
|---|
| Double stack implementation(with structures) |
| Souce code |
| Documentation |
| Test cases |
| Compatibility |
| All Pages |
DOUBLE STACK IMPLEMENTATION
(with structures)
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.
Structure has the following advantages.
-
Clarity
As programs get bigger, they get more confusing if they're not structured. Restricting programming logic to structures that have only one point of exit and entry makes it much easier to track the 'flow' of logic.
-
Efficiency
-
Maintenance
Programs that follow a consistent set of clearly defined structures (having single points of entry and exit) are much easier to read and debug. Especially when maintenance issues arise long after the program is written.
In this program, 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 > |
|---|




