11.7 STACK

Purpose:

The STACK organization provides fast LIFO (last-in first-out) and FIFO (first-in first-out) stacks.

There are three ways of implementing a stack in OrgC++:

  1. As described previously, RINGS can be used as LIFO/FIFO queues.
  2. Special organizations called LIFO and FIFO are internally based on RINGS, but have convenient push() and pop() functions.
  3. The DYNAMIC_ARRAY can be used as a LIFO stack. push() and pop() operations add/delete the top object from the array, and enlarge the array automatically if the array is full.

POP and PUSH operations:

push() pushes a new object onto the stack;
pop() returns the next object and disconnects it from the stack.
When pop() returns NULL, the stack is empty.

Initialization:

When using the RING, LIFO, or FIFO organizations, start=NULL must be set before using the stack. When using the array-style stack, the array must be declared by ZZ_HYPER_ARRAY(), and formed by form() (See Chap.11.15)

Syntax:

ZZ_HYPER_LIFO(id,TYPE);
ZZ_HYPER_FIFO(id,TYPE);
Declare the two types of the queue.
void id.push(TYPE *obj); Pushes the given object into the queue.
TYPE* id.pop(); Pops another object from the queue. When returning NULL, the queue is empty.

Examples:

  1. See the files macro/hyplifo and macro/hypfifo.
  2. test9.c contains a comprehensive test of all ARRAY features.

 

Previous Section 11.6 LINK and NAME Next Section 11.8 ENTITY_RELATIONSHIP MODEL