C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
linked_list.h File Reference

Singly-linked list of int. More...

#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Classes

struct  linked_list_t
 
struct  ll_node
 

Macros

#define LL_NOT_FOUND   ((size_t)-1)
 

Typedefs

typedef struct ll_node ll_node_t
 

Functions

linked_list_tll_create (void)
 
void ll_destroy (linked_list_t *list)
 
size_t ll_find (const linked_list_t *list, int value)
 
bool ll_is_empty (const linked_list_t *list)
 
bool ll_pop_front (linked_list_t *list, int *out_value)
 
bool ll_push_back (linked_list_t *list, int value)
 
bool ll_push_front (linked_list_t *list, int value)
 
void ll_reverse (linked_list_t *list)
 
size_t ll_size (const linked_list_t *list)
 

Detailed Description

Singly-linked list of int.

Designed for clarity over performance. Owns its nodes — ll_destroy frees every node. Caller never touches the node struct directly; all operations go through the list handle.

Operation Time
push_front O(1)
push_back O(n) (no tail pointer cached)
pop_front O(1)
find O(n)
size O(1) (cached)

Definition in file linked_list.h.

Macro Definition Documentation

◆ LL_NOT_FOUND

#define LL_NOT_FOUND   ((size_t)-1)

Definition at line 49 of file linked_list.h.

Typedef Documentation

◆ ll_node_t

typedef struct ll_node ll_node_t

Function Documentation

◆ ll_create()

linked_list_t * ll_create ( void  )

Definition at line 8 of file linked_list.c.

References linked_list_t::head, and linked_list_t::size.

Referenced by main().

◆ ll_destroy()

void ll_destroy ( linked_list_t list)

Definition at line 16 of file linked_list.c.

References linked_list_t::head, and ll_node::next.

Referenced by main().

◆ ll_find()

size_t ll_find ( const linked_list_t list,
int  value 
)

Returns the index of value, or (size_t)-1 if missing.

Definition at line 66 of file linked_list.c.

References linked_list_t::head, and LL_NOT_FOUND.

Referenced by main().

◆ ll_is_empty()

bool ll_is_empty ( const linked_list_t list)

Definition at line 79 of file linked_list.c.

References linked_list_t::size.

◆ ll_pop_front()

bool ll_pop_front ( linked_list_t list,
int *  out_value 
)

Definition at line 56 of file linked_list.c.

References linked_list_t::head, ll_node::next, linked_list_t::size, and ll_node::value.

◆ ll_push_back()

bool ll_push_back ( linked_list_t list,
int  value 
)

Definition at line 38 of file linked_list.c.

References linked_list_t::head, ll_node::next, linked_list_t::size, and ll_node::value.

Referenced by main().

◆ ll_push_front()

bool ll_push_front ( linked_list_t list,
int  value 
)

Definition at line 27 of file linked_list.c.

References linked_list_t::head, ll_node::next, linked_list_t::size, and ll_node::value.

◆ ll_reverse()

void ll_reverse ( linked_list_t list)

Reverses the list in place. O(n).

Definition at line 83 of file linked_list.c.

References linked_list_t::head, and ll_node::next.

Referenced by main().

◆ ll_size()

size_t ll_size ( const linked_list_t list)

Definition at line 75 of file linked_list.c.

References linked_list_t::size.

Referenced by print_list().