diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ll.c | 27 | ||||
-rw-r--r-- | src/lib/q.c | 14 |
2 files changed, 40 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; +} diff --git a/src/lib/q.c b/src/lib/q.c index ebae2b9..2ade143 100644 --- a/src/lib/q.c +++ b/src/lib/q.c @@ -38,3 +38,17 @@ void pop_q(struct Q_base* qb) free(t->data); free(t); } + +unsigned long length_q(struct Q_base* qb) +{ + unsigned long length = 0; + if(qb->next == 0) + return length; + length++; + struct Q* q = qb->next; + while (q != qb->last) { + length++; + q = q->next; + } + return length; +} |