diff options
Diffstat (limited to 'collections')
-rw-r--r-- | collections/double_ended_queue.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/collections/double_ended_queue.c b/collections/double_ended_queue.c index 967a716..88d4641 100644 --- a/collections/double_ended_queue.c +++ b/collections/double_ended_queue.c @@ -117,11 +117,18 @@ void* deq_index(root, index) deq *root; int index; { - if (!root || root->beg + index >= root->end) { + void *tmp; + + if (!root) { + return NULL; + } + + tmp = root->base + (root->beg + index - root->base) % root->limit); + if (tmp > root->end) { return NULL; } - return root->beg[index]; + return *tmp; } void* deq_pop_back(root) |