Website Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
2 files changed, 5 insertions, 7 deletions
-rw-r--r--src/List/List.cpp11
-rw-r--r--src/List/OrderedList.h1
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 <class T>
void List<T>::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<T>::copyFrom(const List& other) {
/* Public */
template <class T>
-List<T>::List(const T* elements, unsigned elementsCount) : List() {
+List<T>::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<T>::get_count() const {
// Rule of 4
template <class T>
-List<T>::List() {
- length = 8;
- count = 0;
- elements = new T[length];
-}
+List<T>::List() : List(nullptr, 0) {}
template <class T>
List<T>& List<T>::operator=(const List& other) {
diff --git a/src/List/OrderedList.h b/src/List/OrderedList.h
index c32ac46..e0b104f 100644
--- a/src/List/OrderedList.h
+++ b/src/List/OrderedList.h
@@ -6,6 +6,7 @@
template <class T>
class OrderedList : public List<T> {
public:
+ OrderedList();
OrderedList(const T* elements, unsigned elementsCount);
void add(const T& element) = delete;