Website Summary Files Commits Branches @commit @diff @stats
path: root / src / List / List.cpp
diff options
context:
space:
mode:
Commitc1c753cbbd384a46c6a81a62e667347299757267 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-28 19:05:37 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-28 19:05:37 +0300
Files2963afb238af487fcaeb202b662d49fe4540b039 /src/List/List.cpp
FMI-OOP-P1_TicketSystem-c1c753cbbd384a46c6a81a62e667347299757267.tar
FMI-OOP-P1_TicketSystem-c1c753cbbd384a46c6a81a62e667347299757267.tar.gz
FMI-OOP-P1_TicketSystem-c1c753cbbd384a46c6a81a62e667347299757267.zip
Parent0a276842037ebd4cf8398f7864ba081475c67471 (diff)
Autocommit at 28.04.2022 @ 19:05
1 files changed, 58 insertions, 0 deletions
-rw-r--r--src/List/List.cpp58
diff --git a/src/List/List.cpp b/src/List/List.cpp
new file mode 100644
index 0000000..a1892dd
--- /dev/null
+++ b/src/List/List.cpp
@@ -0,0 +1,58 @@
+#include "List.h"
+
+/* Private */
+
+template <class T>
+void List<T>::resize() {
+ length <<= 1;
+ T* temp = new T[length];
+ for (int i = 0; i < count; i++)
+ temp[i] = elements[i];
+ delete[] elements;
+ elements = temp;
+}
+
+template <class T>
+void List<T>::free() {
+ delete[] elements;
+}
+
+template <class T>
+void List<T>::copyFrom(const List& other) {
+ elements = new T[other.length];
+ for (int i = 0; i < other.count; i++)
+ elements[i] = other.elements[i];
+ length = other.length;
+ count = other.count;
+}
+
+/* Public */
+
+template <class T>
+void List<T>::add(const T& element) {
+ if (length == count) resize();
+
+ elements[count++] = element;
+}
+
+template <class T>
+bool List<T>::removeAt(unsigned index) {
+ if (index >= count) return false;
+
+ delete elements[index];
+ for (int i = index; i < count; i++)
+ elements[i] = elements[i + 1];
+ elements[count--] = nullptr;
+}
+
+template <class T>
+T& List<T>::operator[](unsigned index) {
+ return elements[index];
+}
+
+// Rule of 4
+
+template <class T>
+List<T>::List() {
+
+}