lifo.h¶
LIFO buffer API, read long description carefully.
This LIFO implementation very efficiently handles integer values. The caveat is that it can only handle values between 0 and its own size - 1. Also it can only handle up to one element of each value. If you insert a value twice the LIFO will break.
-
int
lifo_empty
(int * array)¶ Check if the given lifo is empty.
Parameters
array: The lifo array to check. Return values
- 1, if empty
- 0, otherwise.
-
void
lifo_init
(int * array, int n)¶ Initialize a lifo array.
Parameters
array: An array of size n + 1. Must not be NULL
.n: Maximum integer value the lifo is able to store.
-
void
lifo_insert
(int * array, int i)¶ Insert an element into the lifo.
Parameters
array: An integer array of least i + 1 size that **does not already contain *i***. Must not be NULL
.i: The integer value to store, between 0 and the size of the array - 1, must not be stored already.
-
int
lifo_get
(int * array)¶ Extract the least recently inserted element from the lifo.
Parameters
array: An integer array. Must not be NULL. Return values
- -1, if the lifo is empty.
- the least recently inserted element, otherwise.