From e6af2f70ec910ee8cb3813fa1e5b1c7d6e3ead60 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Fri, 3 Jul 2020 23:49:15 -0400 Subject: Add insert function for vectors --- collections/vector/vector.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'collections/vector/vector.c') diff --git a/collections/vector/vector.c b/collections/vector/vector.c index 79e31a4..2ae748f 100644 --- a/collections/vector/vector.c +++ b/collections/vector/vector.c @@ -174,6 +174,23 @@ int index; return root->base[index]; } +void vec_insert(root, index, item) +vec *root; +int index; +void *item; +{ + if (!root || index > root->end || index < 0) + return; + + if (root->end >= root->limit) + vec_resize(root); + + memmove(root->base + index + 1, root->base + index, + (root->end++ - index) * sizeof(void*)); + + root->base[index] = item; +} + void vec_swap(root, i, j) vec *root; int i,j; -- cgit v1.1