aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ll.c')
-rw-r--r--src/lib/ll.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/ll.c b/src/lib/ll.c
index 4eaa291..4918194 100644
--- a/src/lib/ll.c
+++ b/src/lib/ll.c
@@ -13,13 +13,24 @@ struct LL* new_ll(void* val)
void push_ll(struct LL* l, void* val)
{
struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
+ l->prev->next = ll;
ll->prev = l->prev;
ll->next = l;
- ll->prev->next = ll;
l->prev = ll;
ll->data = val;
}
+void pop_ll(struct LL* l)
+{
+ if ((l->prev == l->next) && (l->prev == l))
+ l->data = 0;
+ else {
+ l->prev->next = l->next;
+ l->next->prev = l->prev;
+ free(l);
+ }
+}
+
void remove_ll(struct LL* l, unsigned long idx)
{
struct LL* t = l;
@@ -30,3 +41,17 @@ void remove_ll(struct LL* l, unsigned long idx)
t->next->prev = t->prev;
free(t);
}
+
+unsigned long length_ll(struct LL* l)
+{
+ struct LL* t = l;
+ unsigned long len = 0;
+ while (1) {
+ if (t->next == l) {
+ return len;
+ }
+ len++;
+ t = t->next;
+ }
+ return len;
+}