osurs  0.0.1
Functions
stack.c File Reference

Stack data structure. More...

#include "osurs/ds/stack.h"
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for stack.c:

Functions

void stack_init (Stack *stack)
 Initialize a Stack structure. More...
 
Stackstack_create ()
 Create a new Stack structure. More...
 
bool stack_is_empty (Stack *stack)
 Check if a Stack is empty. More...
 
void stack_push (Stack *stack, void *data)
 Push an element onto a Stack. More...
 
void * stack_pop (Stack *stack)
 Pop the top element from a Stack. More...
 
void * stack_peek (Stack *stack)
 Return the top element of a Stack. More...
 
void stack_clear (Stack *stack)
 Clear all elements from a Stack. More...
 
void stack_free (Stack *stack)
 Free a Stack structure. More...
 

Detailed Description

Stack data structure.

Date
: 2022-12-21
Author
: Merlin Unterfinger

Function Documentation

◆ stack_clear()

void stack_clear ( Stack stack)

Clear all elements from a Stack.

This function removes all elements from a Stack, but does not free the stack structure itself.

Parameters
stackThe Stack to be cleared.

◆ stack_create()

Stack* stack_create ( )

Create a new Stack structure.

This function creates a new Stack structure and returns a pointer to it. The new structure is initialized with its top pointer set to NULL and its size set to 0.

Returns
A pointer to the new Stack structure.

◆ stack_free()

void stack_free ( Stack stack)

Free a Stack structure.

This function frees a Stack structure, including all nodes and their data.

Parameters
stackThe Stack structure to be freed.

◆ stack_init()

void stack_init ( Stack stack)

Initialize a Stack structure.

This function initializes a Stack structure by setting its top pointer to NULL and its size to 0.

Parameters
stackThe Stack structure to be initialized.

◆ stack_is_empty()

bool stack_is_empty ( Stack stack)

Check if a Stack is empty.

This function checks if a Stack is empty (contains no elements).

Parameters
stackThe Stack to be checked.
Returns
true if the stack is empty, false otherwise.

◆ stack_peek()

void* stack_peek ( Stack stack)

Return the top element of a Stack.

This function returns a pointer to the element at the top of a Stack, without removing it from the stack. If the stack is empty, the function returns NULL.

Parameters
stackThe Stack from which the top element will be returned.
Returns
The element at the top of the stack, or NULL if the stack is empty.

◆ stack_pop()

void* stack_pop ( Stack stack)

Pop the top element from a Stack.

This function removes the element at the top of a Stack and returns a pointer to it. If the stack is empty, the function returns NULL.

Parameters
stackThe Stack from which the element will be removed.
Returns
The element at the top of the stack, or NULL if the stack is empty.

◆ stack_push()

void stack_push ( Stack stack,
void *  data 
)

Push an element onto a Stack.

This function pushes an element onto the top of a Stack.

Parameters
stackThe Stack onto which the element will be pushed.
dataThe element to be pushed onto the stack.