Website Summary Files Commits Branches @commit @diff @stats
path: root / src / List / List.cpp
diff options
context:
space:
mode:
Commitcfa3d3129c9269d552fa3345e0952db8efda27d6 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-02 22:15:48 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-02 22:15:48 +0300
Files6886b507f763c592370e6656c3289bf4988c8be1 /src/List/List.cpp
FMI-OOP-P1_TicketSystem-cfa3d3129c9269d552fa3345e0952db8efda27d6.tar
FMI-OOP-P1_TicketSystem-cfa3d3129c9269d552fa3345e0952db8efda27d6.tar.gz
FMI-OOP-P1_TicketSystem-cfa3d3129c9269d552fa3345e0952db8efda27d6.zip
Parenta638207b4697c31a358525f6bfde89328746ff30 (diff)
Autocommit at 02.05.2022 @ 22:15
1 files changed, 4 insertions, 7 deletions
-rw-r--r--src/List/List.cpp11
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) {