diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2020-05-26 01:19:31 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2020-05-26 02:20:22 -0400 |
commit | c3f2eed02152d5902fa26a625d11207e64301849 (patch) | |
tree | 75153f97de48ac9225d40bf14c84b0e737936618 | |
parent | 68b53a55f308d02be02130ef32038b6d707a6b55 (diff) |
Fix push front for double ended queue.
Was only a copy of push back.
-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 81bee47..8a6a91e 100644 --- a/collections/double_ended_queue.c +++ b/collections/double_ended_queue.c @@ -104,14 +104,19 @@ void deq_push_front(root, item) deq *root; void *item; { + void *tmp; + if (!root) { return; } - if (root->end == root->base + root->limit) { + + tmp = (root->base + ((root->beg - 1) - root->base) % root->limit); + if (tmp == root->beg) { deq_resize(root); + tmp = (root->base + ((root->beg - 1) - root->base) % root->limit); } - *(root->end++) = item; + *(root->beg = tmp) = item; } void* deq_pop_front(root) |