libdatatypes 0.3.2
Abstract datatypes for C.
Loading...
Searching...
No Matches
stack.h File Reference

Generic stack. More...

#include "slist.h"

Go to the source code of this file.

Macros

#define stack_new(compare, free, pool)   slist_new(compare, free, pool)
 
#define stack_init(stack, compare, free, pool)   slist_init(stack, compare, free, pool)
 
#define stack_destroy(stack)   slist_destroy(stack)
 
#define stack_free(stack)   slist_free(stack)
 
#define stack_push(stack, data)   slist_prepend(stack, data)
 
#define stack_clear(stack)   slist_clear(stack)
 
#define stack_count(stack)   slist_count(stack)
 

Typedefs

typedef SList Stack
 Generic stack.
 
typedef SList StackItem
 Holds stack item data & pointer to next element.
 

Functions

bool stack_head (const Stack *stack, void **data)
 
bool stack_pop (Stack *stack, void **data)
 

Detailed Description

Generic stack.

Author
Sebastian Fedrau sebas.nosp@m.tian.nosp@m..fedr.nosp@m.au@g.nosp@m.mail..nosp@m.com

Definition in file stack.h.

Macro Definition Documentation

◆ stack_clear

#define stack_clear (   stack)    slist_clear(stack)
Parameters
stacka Stack

Clears a stack.

Definition at line 104 of file stack.h.

◆ stack_count

#define stack_count (   stack)    slist_count(stack)
Parameters
stacka Stack
Returns
number of items

Gets the number of stored items.

Definition at line 112 of file stack.h.

◆ stack_destroy

#define stack_destroy (   stack)    slist_destroy(stack)
Parameters
stacka Stack

Frees all items in the stack and the stack pointer.

Definition at line 64 of file stack.h.

◆ stack_free

#define stack_free (   stack)    slist_free(stack)
Parameters
stacka Stack

Frees all items in the stack without freeing the stack pointer.

Definition at line 71 of file stack.h.

◆ stack_init

#define stack_init (   stack,
  compare,
  free,
  pool 
)    slist_init(stack, compare, free, pool)
Parameters
stacka Stack
comparefunction to compare item data
freefunction to free item data or NULL
poola user-defined memory pool for creating/destroying StackItems or NULL

Initializes a Stack.

Definition at line 57 of file stack.h.

◆ stack_new

#define stack_new (   compare,
  free,
  pool 
)    slist_new(compare, free, pool)
Parameters
comparefunction to compare item data
freefunction to free item data or NULL
poola user-defined memory pool for creating/destroying StackItems or NULL
Returns
a new Stack

Creates a new Stack.

Definition at line 47 of file stack.h.

◆ stack_push

#define stack_push (   stack,
  data 
)    slist_prepend(stack, data)
Parameters
stacka Stack
datadata to push

Pushs data onto the stack.

Definition at line 79 of file stack.h.

Typedef Documentation

◆ Stack

Generic stack.

Definition at line 31 of file stack.h.

◆ StackItem

Holds stack item data & pointer to next element.

Definition at line 37 of file stack.h.

Function Documentation

◆ stack_head()

bool stack_head ( const Stack stack,
void **  data 
)
Parameters
stacka Stack
datalocation to store data
Returns
true if stack is not empty

Gets first element from stack without removing it.

Definition at line 55 of file stack.c.

◆ stack_pop()

bool stack_pop ( Stack stack,
void **  data 
)
Parameters
stacka Stack
datalocation to store data
Returns
true if stack is not empty

Pops the first element from the stack.

Definition at line 28 of file stack.c.