A Slightly Confused Applet
It is well known that a stack can be implemented by a pointer plus an array, where the pointer is represented as a cell containing a natural number. The Java applet below illustrates the behavior of both the stack abstraction and this particular implementation. Here a stack of depth n has n in the cell, and has its n elements in places 0,...,n-1 of the array. The two buttons call the PUSH and POP methods.

This is an animate (i.e., interactive) beast, so you must TRY IT to understand it. Can you see what's wrong with this applet? (Also, what about the choice of colors?)

It is interesting to notice that there may also be elements above the pointer, i.e., in a place greater than n-1. (This clever applet was written by Dr Grant Malcolm to illustrate a behavioral correctness proof in the CafeOBJ library website; thanks to him for permission to exhibit it in our zoo.)



To UCSZ homepage.
To Tatami project homepage.
To UCSD Meaning and Computation Lab homepage.
To my homepage.
10 January 1998; version of 23 January 2000.