From cfa3d3129c9269d552fa3345e0952db8efda27d6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 2 May 2022 22:15:48 +0300 Subject: Autocommit at 02.05.2022 @ 22:15 --- src/List/List.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/List/List.cpp') diff --git a/src/List/List.cpp b/src/List/List.cpp index d455c04..e5b360c 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -4,7 +4,7 @@ template void List::resize() { - length <<= 1; + length = (length == 0) ? 8 : length << 1; T* temp = new T[length]; for (int i = 0; i < count; i++) temp[i] = elements[i]; @@ -29,7 +29,8 @@ void List::copyFrom(const List& other) { /* Public */ template -List::List(const T* elements, unsigned elementsCount) : List() { +List::List(const T* elements, unsigned elementsCount) { + count = length = 0; for (unsigned i = 0; i < elementsCount; i++) add(elements[i]); } @@ -124,11 +125,7 @@ unsigned List::get_count() const { // Rule of 4 template -List::List() { - length = 8; - count = 0; - elements = new T[length]; -} +List::List() : List(nullptr, 0) {} template List& List::operator=(const List& other) { -- cgit v1.3.1-23-gd82d