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.adoc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'collections/vector/vector.adoc') diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc index 3fe2dbf..d439c85 100644 --- a/collections/vector/vector.adoc +++ b/collections/vector/vector.adoc @@ -1,7 +1,7 @@ Vector ====== Tucker Evans -v0.8.1, 2020-07-03 +v0.9, 2020-07-03 A basic vector, that hold pointers to your data structures. @@ -186,6 +186,29 @@ assert(str_cmp(vec_pop(vector), str2) == 0); assert(str_cmp(vec_pop(vector), str1) == 0); ---- +[[vec_back]] ++void* vec_back(vec *self)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Returns the element at the back of the vector +self+. + +Examples +^^^^^^^^ +[source,c] +---- +#include "vector.h" +#include + +char *str1 = "ONE"; +char *str2 = "TWO"; + +vec *vector = vec_new(); +vec_push(vector, str_dup(str1)); +vec_push(vector, str_dup(str2)); + +assert(strcmp(vec_back(vector), str2) == 0); +---- + + [[vec_index]] +void* vec_index(vec *self, int index)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.1