12.7 Using a darray as a stack
It is possible to use a darray as a stack. The darray is initialised as
normal, but certain functions are provided to perform the stack
operations. Of course, array and stack operations may be freely
intermingled (although this is unlikely to be useful). When using a
darray as a stack, the `top' of the stack is the high end of the darray.
— Function: int
da_empty (
const Darray *da)
Returns non-zero iff da has zero elements. Equivalent to the
following:
da_length (da) == 0
— Function: int
da_push (
const Darray *da, const void *element)
Equivalent to ‘da_append’.
— Function: void
da_pop (
Darray *da, void *elt_buf)
Copies the contents of the last member of da into elt_buf, and
deletes that member from da.
— Function: void
da_drop (
Darray *da)
Deletes the last member of da.
— Function: void *
da_top (
Darray *da)
Equivalent to ‘da_last’.
— Function: void
da_swap (
Darray *da)
Exchanges the top and next-to-top elements of da. da must have at
least two elements.
— Function: int
da_dup (
Darray *da)
Pushes on da a copy of its topmost element. da must have at
least one element. Returns 0 if the function succeeded, or -1 if
there was insufficient memory.