diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-05-25 01:22:01 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2020-05-26 02:20:22 -0400 |
commit | 68b53a55f308d02be02130ef32038b6d707a6b55 (patch) | |
tree | 868eed5d0486f416ab97397d2bbd9d940bfe2f91 | |
parent | 6eb63be564e5d99e9ead3c10e98ab684363428f2 (diff) |
Fix double ended queue push back.
-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 a49b018..81bee47 100644 --- a/collections/double_ended_queue.c +++ b/collections/double_ended_queue.c @@ -7,6 +7,10 @@ #define START_SIZE 64; +/*TODO add returned error codes for current void functions + * (resize, push, etc.) + */ + struct double_ended_queue { void **base, **end, **beg; int limit; @@ -86,11 +90,14 @@ void *item; if (!root) { return; } - if (root->end == root->base + root->limit) { + + tmp = (root->base + (root->end - root->base) % root->limit); + if (tmp == root->beg) { deq_resize(root); + tmp = (root->base + (root->end - root->base) % root->limit); } - *(root->end++) = item; + *(root->end = tmp) = item; } void deq_push_front(root, item) |