diff options
Autocommit at 28.05.2022 @ 17:54
1 files changed, 11 insertions, 0 deletions
| -rw-r--r-- | src/Generic/List/List.hpp | 11 |
diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index 0b53033..f1919b3 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -32,6 +32,8 @@ protected: public: //! Copies all elements in given array List(const T* elements, unsigned elementsCount); + //! Allocates memory for the given length + List(unsigned length); //! Adds an element void add(const T& element); //! Inserts element at given index @@ -112,6 +114,15 @@ List<T>::List(const T* elements, unsigned elementsCount) { this->elements[i] = elements[i]; } +template <typename T> +List<T>::List(unsigned length) { + this->length = length; + count = 0; + this->elements = new T[length]; + for (unsigned i = 0; i < count; i++) + this->elements[i] = elements[i]; +} + /*! * Resizes internal array if there is no space for additional elements. */ |
