A method, system, and apparatus for placing and removing data elements into a
bi-directionally
growing first in last out data structure is provided. In one embodiment, in response
to a request to place a data element into the data structure, a head pointer is
advanced one memory location in a direction indicated by a state of a direction
flag. The new data element is placed into the memory location indicated by the
head pointer. The position of the head pointer and the base pointer are swapped
in preparation for receiving a new data element and the state of the direction
flag is reversed to indicate growth of the data structure in the opposite direction.
In response to a request to remove a data element from the data structure, the
head and base pointers are swapped and the state of the direction flag is reversed.
The element indicated by the location pointed to by the head pointer is removed
and the head pointer retreats one memory location position in a direction opposite
the direction indicated by the direction flag.