data_structures
Typedefs | Functions
stack.h File Reference
#include <errno.h>
#include <sys/types.h>
#include "types.h"
#include "array.h"
#include "utils.h"
+ Include dependency graph for stack.h:

Go to the source code of this file.

Typedefs

typedef t_array t_stack
 A last-in-first-out stack of generic items. More...
 

Functions

void stack_push (t_stack *stack, const void *data)
 Copy the item and add it to the stack. More...
 
void * stack_pop (t_stack *stack)
 Removed and returns the item most recently added to this stack. More...
 
void * stack_peek (const t_stack *stack)
 Returns the item most recently added to this stack, without removing it. More...
 
void stack_delete (t_stack *stack)
 Deletes the stack and frees memory taken by its contents. More...
 
size_t stack_size (const t_stack *stack)
 Returns the number of items in this stack. More...
 
t_stackstack_new (const t_type *type)
 Initializes an empty stack. More...
 
t_stackstack_copy (const t_stack *stack)
 Copies a stack and all it contents. More...
 

Typedef Documentation

◆ t_stack

typedef t_array t_stack

A last-in-first-out stack of generic items.

Implemented using a resizable array.

Definition at line 29 of file stack.h.

Function Documentation

◆ stack_copy()

t_stack* stack_copy ( const t_stack stack)

Copies a stack and all it contents.

Returns
A copy of the stack

Definition at line 16 of file stack_copy.c.

◆ stack_delete()

void stack_delete ( t_stack stack)

Deletes the stack and frees memory taken by its contents.

Definition at line 16 of file stack_delete.c.

◆ stack_new()

t_stack* stack_new ( const t_type type)

Initializes an empty stack.

Parameters
typethe type of items that this stack will hold
Returns
The new stack

Definition at line 16 of file stack_new.c.

◆ stack_peek()

void* stack_peek ( const t_stack stack)

Returns the item most recently added to this stack, without removing it.

Returns
the item most recently added, or NULL if the stack is empty.

Definition at line 16 of file stack_peek.c.

◆ stack_pop()

void* stack_pop ( t_stack stack)

Removed and returns the item most recently added to this stack.

Returns
the item most recently added, or NULL if the stack is empty.

Definition at line 16 of file stack_pop.c.

◆ stack_push()

void stack_push ( t_stack stack,
const void *  data 
)

Copy the item and add it to the stack.

Parameters
dataThe item to be added

Definition at line 16 of file stack_push.c.

◆ stack_size()

size_t stack_size ( const t_stack stack)

Returns the number of items in this stack.

Returns
the number of items in this stack

Definition at line 16 of file stack_size.c.