From 7d8eabf47938ff4a056f94e8cbeb4a49ab9ea2d1 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Wed, 8 Jan 2020 11:01:18 +0100 Subject: [PATCH] arraylsits can now reserve --- arraylist.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arraylist.hpp b/arraylist.hpp index 709bd07..6590b22 100644 --- a/arraylist.hpp +++ b/arraylist.hpp @@ -51,6 +51,13 @@ struct Array_List { next_index++; } + void reserve(unsigned int count) { + if (next_index+count <= length) { + length *= 2; + data = (type*)realloc(data, length * sizeof(type)); + } + } + type& operator[](int index) { return data[index]; }