The Stack Library  0.2.1
Functions
stack.c File Reference

Source for Stack Library (CDSL) More...

#include <stddef.h>
#include "cbl/assert.h"
#include "cbl/memory.h"
#include "stack.h"
Include dependency graph for stack.c:

Functions

stack_t *() stack_new (void)
 creates a stack.
int() stack_empty (const stack_t *stk)
 inspects if a stack is empty.
void() stack_push (stack_t *stk, void *data)
 pushes data into a stack.
void *() stack_pop (stack_t *stk)
 pops data from a stack.
void *() stack_peek (const stack_t *stk)
 peeks the top-most data in a stack.
void() stack_free (stack_t **stk)
 destroys a stack.

Detailed Description

Source for Stack Library (CDSL)


Function Documentation

int() stack_empty ( const stack_t stk)

inspects if a stack is empty.

stack_empty() inspects if a stack is empty.

Possible exceptions: assert_exceptfail

Unchecked erros: foreign data structure given for stk

Parameters:
[in]stkstack to inspect
Returns:
whether stack is empty or not
Return values:
1empty
0not empty
void() stack_free ( stack_t **  stk)

destroys a stack.

stack_free() deallocates all storages for a stack and set the pointer passed through stk to a null pointer. Note that stack_free() does not deallocate any storage for the data in the stack to destroy, which must be done by a user.

Possible exceptions: assert_exceptfail

Unchecked errors: foreign data structure given for stk

Warning:
The storage allocated for data (whose address a stack's node possesses) is never touched; its allocation and deallocation is entirely up to the user.
Parameters:
[in,out]stkpointer to stack to destroy
Returns:
nothing
stack_t*() stack_new ( void  )

creates a stack.

stack_new() creates a new stack and sets its relevant information to the initial.

Possible exceptions: mem_exceptfail

Unchecked errors: none

Returns:
created stack
void*() stack_peek ( const stack_t stk)

peeks the top-most data in a stack.

stack_peek() provides a way to inspect the top-most data in a stack without popping it up.

Possible exceptions:

Unchecked errors:

Parameters:
[in]stkstack to peek
Returns:
top-most data in stack
void*() stack_pop ( stack_t stk)

pops data from a stack.

stack_pop() pops data from a stack. If the stack is empty, an exception is raised due to the assertion failure, so popping all data without knowing the number of nodes remained in the stack needs to use stack_empty() to decide when to stop.

Possible exceptions: assert_exceptfail

Unchecked errors: foreign data structure given for stk

Parameters:
[in,out]stkstack from which data popped
Returns:
data popped from stack
void() stack_push ( stack_t stk,
void *  data 
)

pushes data into a stack.

stack_push() pushes data into the top of a stack. There is no explicit limit on the maximum number of data that can be pushed into a stack.

Possible exceptions: mem_exceptfail, assert_exceptfail

Unchecked errors: foreign data structure given for stk

Parameters:
[in,out]stkstack into which given data pushed
[in]datadata to push
Returns:
nothing
 All Files Functions Typedefs