Go to the source code of this file.
|
typedef struct internal_deque * | stack |
|
◆ stack
typedef struct internal_deque* stack |
The stack data structure, which adapts a container to provide a stack (last-in first-out). Adapts the deque container.
◆ stack_clear()
Clears the stack and sets it to the state from original initialization.
- Parameters
-
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
◆ stack_copy_to_array()
void stack_copy_to_array |
( |
void *const |
arr, |
|
|
stack |
me |
|
) |
| |
Copies the stack to an array. Since it is a copy, the array may be modified without causing side effects to the stack data structure. Memory is not allocated, thus the array being used for the copy must be allocated before this function is called.
- Parameters
-
arr | the initialized array to copy the stack to |
me | the stack to copy to the array |
◆ stack_destroy()
Frees the stack memory. Performing further operations after calling this function results in undefined behavior. Freeing NULL is legal, and causes no operation to be performed.
- Parameters
-
- Returns
- NULL
◆ stack_init()
stack stack_init |
( |
const size_t |
data_size | ) |
|
Initializes a stack.
- Parameters
-
data_size | the size of each data element in the stack; must be positive |
- Returns
- the newly-initialized stack, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error
◆ stack_is_empty()
Determines if the stack is empty, meaning it contains no elements.
- Parameters
-
me | the stack to check if empty |
- Returns
- BK_TRUE if the stack is empty, otherwise BK_FALSE
◆ stack_pop()
Removes the top element of the stack, and copies the data which is being removed. The pointer to the data being obtained should point to the data type which this stack holds. For example, if this stack holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.
- Parameters
-
data | the copy of the element being removed |
me | the stack to remove the top element from |
- Returns
- BK_TRUE if the stack contained elements, otherwise BK_FALSE
◆ stack_push()
Adds an element to the top of the stack. The pointer to the data being passed in should point to the data type which this stack holds. For example, if this stack holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.
- Parameters
-
me | the stack to add an element to |
data | the data to add to the stack |
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
-
-BK_ERANGE if size has reached representable limit
◆ stack_size()
size_t stack_size |
( |
stack |
me | ) |
|
Determines the size of the stack.
- Parameters
-
me | the stack to check size of |
- Returns
- the size of the stack
◆ stack_top()
Copies the top element of the stack. The pointer to the data being obtained should point to the data type which this stack holds. For example, if this stack holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.
- Parameters
-
data | the copy of the top element of the stack |
me | the stack to copy from |
- Returns
- BK_TRUE if the stack contained elements, otherwise BK_FALSE
◆ stack_trim()
Frees unused memory from the stack.
- Parameters
-
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory