Two stacks can share a fixed array by growing inwards from opposite ends. Store one stack in and the other in , with representation invariant . The first top is at , the second at , and is free. The abstraction function reads the first segment backwards and the second forwards to obtain top-first lists. Push requires ; a pop requires its own stack to be nonempty. Every operation uses constant time, and either stack can use all remaining space. The bounded abstract data type must expose or specify the shared capacity restriction.

Articles by others on the same topic (0)

There are currently no matching articles.