osurs  0.0.1
Data Structures | Typedefs | Functions
stack.h File Reference

Stack data structure. More...

#include <stdbool.h>
#include <stddef.h>
Include dependency graph for stack.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  StackNode
 Stack node. More...
 
struct  Stack
 Stack. More...
 

Typedefs

typedef struct StackNode StackNode
 Stack node. More...
 
typedef struct Stack Stack
 Stack. More...
 

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.

This file defines a Stack data structure, which is an abstract data type (ADT) that implements a LIFO (last-in, first-out) stack. Elements can be inserted at the top and removed from the top.

Date
2022-12-21
Author
Merlin Unterfinger

Typedef Documentation

◆ Stack

typedef struct Stack Stack

Stack.

This structure represents a Stack data structure. It consists of a pointer to the top of the stack (the node at the top of the stack) and an integer size representing the number of elements in the stack.

◆ StackNode

typedef struct StackNode StackNode

Stack node.

This structure represents a node in a Stack data structure. It consists of a void pointer to the node's data and a pointer to the next node in the stack.

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.