blob: 4eaa2910a32f2b751f90cb0a866b8b1095f1a5f6 (
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_ll(void* val)
{
struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
ll->prev = ll;
ll->next = ll;
ll->data = val;
return ll;
}
void push_ll(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_ll(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);
}
|