codex
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1#ifndef CODEX_LIST_H
2#define CODEX_LIST_H
3
4#include <stddef.h>
5
6struct node {
7 struct node *next;
8 int i;
9};
10
11static inline void list_push_front(struct node **l, struct node *n) {
12 n->next = *l;
13 *l = n;
14}
15
16static inline struct node *list_reverse(struct node *n) {
17 struct node *ret = NULL;
18 for(struct node *next = NULL; n; n = next) {
19 next = n->next;
20 list_push_front(&ret, n);
21 }
22 return ret;
23}
24
25static inline struct node *list_remove(struct node **n, int i) {
26 for(; *n; n = &(*n)->next) {
27 if((*n)->i != i)
28 continue;
29 struct node *const ret = *n;
30 *n = ret->next;
31 return ret;
32 }
33 return NULL;
34}
35
36#endif
static struct node * list_reverse(struct node *n)
Definition list.h:16
static void list_push_front(struct node **l, struct node *n)
Definition list.h:11
static struct node * list_remove(struct node **n, int i)
Definition list.h:25
Definition list.h:6
int i
Definition list.h:8
struct node * next
Definition list.h:7