diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-06-10 23:37:15 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-06-10 23:46:57 -0400 |
commit | 277e14127bbe1a5080a2a88b6ee3ef94859bc3a5 (patch) | |
tree | a5d35861acfa3efa9ef29911529c4fd9bb6d14ba /collections/double_ended_queue.adoc | |
parent | 0f7085dedd2f60f2ccc0b1f49558f5be89de97b2 (diff) |
Add insert function to double ended queue.
Diffstat (limited to 'collections/double_ended_queue.adoc')
-rw-r--r-- | collections/double_ended_queue.adoc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/collections/double_ended_queue.adoc b/collections/double_ended_queue.adoc index f583df3..70cbbaf 100644 --- a/collections/double_ended_queue.adoc +++ b/collections/double_ended_queue.adoc @@ -1,7 +1,7 @@ Double Ended Queue ================== Tucker Evans -v0.1, 2020-06-10 +v0.2, 2020-06-10 A double ended queue implemented in a circular buffer. @@ -200,6 +200,32 @@ assert(str_cmp(deq_pop_back(queue), str2) == 0); assert(str_cmp(deq_pop_back(queue), str2) == 0); ---- ++void deq_insert(deq *self, int index, void *item)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Inserts +item+ into queue +self+ at index +index+, all items after the index +are pushed toward the end. + +Examples +^^^^^^^^ +[source,c] +---- +#include "double_ended_queue.h" +#include <string.h> + +char *str1 = "ONE"; +char *str2 = "TWO"; +char *str3 = "THREE"; + +deq *queue = deq_new(); +deq_push_back(queue, str_dup(str1)); +deq_push_back(queue, str_dup(str2)); + +deq_insert(queue, 1, str_dup(str3)); + +assert(str_cmp(deq_index(queue, 1), str3) == 0); +assert(str_cmp(deq_index(queue, 2), str2) == 0); +---- + +void* deq_pop_front(deq *self)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Pops an item off of the front of the queue +self+. |