next up previous index
Next: The Stack as a Up: Data Structures Previous: Code and Demonstration   Index

Linked Implementations

We previously implemented stacks and queues by means of arrays. At the same time we noted that the Stack interface, for instance, might be implemented in other ways. That was the purpose of separating the specification of the interface from any particular implementation. To recall, here is the interface again.

public interface Stack {
    public boolean isEmpty();
    public void push(Object item);
    public Object pop();
}

One of the problems that we had to deal with, when using arrays, was the need to grow the array dynamically if it threatened to overflow; and this involved copying the old array into the new one. The present solution is to create a single new storage element for each item pushed onto the stack. This is assumed to be recovered by the garbage collector once that item is popped.



Subsections

Peter Williams 2005-06-07