Files
link/include/link.h
2026-03-10 19:01:36 -05:00

45 lines
1.1 KiB
C

#ifndef LINK_INCLUDED
#define LINK_INCLUDED
#include <stdbool.h>
#include <stdint.h>
struct Node {
uint64_t id; // For Example
struct Node *next; // Link
};
typedef struct Node Node;
// Syntactic Sugar
typedef struct Node * List;
typedef struct Node * Stack;
typedef struct Node * Queue;
// Alloc a new node, can RAISE oom Exception.
extern struct Node *node_alloc( uint64_t id );
// Callback function prototype
typedef void (*Callback)(Node *);
extern void list_for_each(List *l, Callback callback);
extern void list_free(List *l);
extern void list_print(List *l);
// CRUD by Index. 0 is the beginning, -1 will be treated as the end.
extern bool list_insert_at(List *l, struct Node *n, int index);
extern uint64_t list_delete_at(List *l, int index);
extern uint64_t list_search_at(List *l, int index);
// Read and Delete by ID(or whatever).
extern bool list_search_id(List *l, uint64_t id);
extern bool list_delete_id(List *l, uint64_t id);
// Stacks
extern bool stack_push(Stack *s, struct Node *n);
extern uint64_t stack_pop(Stack *s);
// Queues
extern bool q_enqueue(Queue *q, struct Node *n);
extern uint64_t q_dequeue(Queue *q);
#endif