aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ll.c
blob: 6d96f456a65b6bcfb353ae1007da575557bfa019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "../lib/ll.h"
#include "../lib/mem.h"

struct LL* new(void* val)
{
	struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
	ll->prev = ll;
	ll->next = ll;
	ll->data = val;
	return ll;
}

void push(struct LL* l, void* val)
{
	struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
	ll->prev = l->prev;
	ll->next = l;
	ll->prev->next = ll;
	l->prev = ll;
	ll->data = val;
}

void remove(struct LL* l, unsigned long idx)
{
	struct LL* t = l;
	for(unsigned long i = 0; i < idx; i++) {
		t = t->next;
	}
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}