diff options
-rw-r--r-- | collections/double_ended_queue.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/collections/double_ended_queue.c b/collections/double_ended_queue.c index 88d4641..a49b018 100644 --- a/collections/double_ended_queue.c +++ b/collections/double_ended_queue.c @@ -9,7 +9,7 @@ struct double_ended_queue { void **base, **end, **beg; - int i, limit; + int limit; }; deq* deq_new() @@ -47,7 +47,12 @@ deq *root; if (!root) { return -1; } - return (root->end - root->beg); + + if (root->beg <= root->end) { + return (root->end - root->beg); + } + + return (root->base + root->limit - root->beg) + (root->end - root->base); } void deq_resize(root) |