From f900066b813fac2f34798c39f16dacda9a878610 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Fri, 3 Jul 2020 00:52:26 -0400 Subject: Add back function to vectors back() returns the element in the last position without removing it. --- collections/vector/vector.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'collections/vector/vector.c') diff --git a/collections/vector/vector.c b/collections/vector/vector.c index b8f83de..0b816b7 100644 --- a/collections/vector/vector.c +++ b/collections/vector/vector.c @@ -142,6 +142,16 @@ vec *root; return root->base[--root->end]; } +void* vec_back(root) +vec *root; +{ + if (!root || root->end == 0) { + return NULL; + } + + return root->base[root->end - 1]; +} + void* vec_index(root, index) vec *root; int index; -- cgit v1.1